Reputation: 11132
I'm building a formset like so:
InterestFormSet = modelformset_factory(Interest, \
formset=BaseInterestFormSet, exclude=('userid',), extra=2)
And I want set default labels and values for elements of this form.
I know that in simple forms I can use the fields
dict to change these things for specific fields of the form, but how is this done with a formset?
I tried extending the formset (as you can see) to see if I could access self.fields
from within __init__
, but no luck.
Upvotes: 1
Views: 235
Reputation: 1597
Something like this should do what you want:
class InterestForm(ModelForm):
pub_date = DateField(label='Publication date')
class Meta:
model = Interest
exclude = ('userid',)
InterestFormSet = modelformset_factory(Interest, form=InterestForm, extra=2)
Upvotes: 1
Reputation: 16346
Formsets don't have fields, they only have forms which have fields. So you have to deal directly with those forms.
Upvotes: 0