I have a form that is a subclass of BaseInlineFormSet, and for one of the fields in the related model, I like to change its widget. Here is my code for the form:
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}}
Any help and input is appreciated
An inline formset is a collection of model forms. The
Metaclass doesn’t belong on the formset, it belongs on a model form.Usually, you would create the inline formset class using the
inlineformset_factorymethod, which can takeformas an argument.If you do have to subclass
BaseInlineFormset, you can provide formset as an argument toinlineformset_factoryas well.Have a look at the inline formset documentation for more information.