我有一个表单,它是 BaseInlineFormSet 的子类,对于相关模型中的一个字段,我喜欢更改它的小部件。这是我的表单代码:
class MyForm(forms.models.BaseInlineFormSet):
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.forms[0].error_css_class = 'error'
self.forms[0].required_css_class = 'required'
class Meta:
model = MyModel
# here I am trying.
# recommend is an IntegerField in MyModel, which -
# I like to make it render in the form as a Radio Select (yes, no)
widgets = {'recommend': {forms.RadioSelect}}
任何帮助和意见表示赞赏