views:

589

answers:

2

In a Django ModelForm, you can change the widget type of a field like so:

class EntryForm(ModelForm):
    entity = forms.CharField()

    class Meta:
        model = Entry

I can easily create a modelformset from the same model like so:

EntryFormSet = modelformset_factory(Entry)

But is there a way to include the input field type change change when creating a modelformset?

+3  A: 

modelformset_factory takes a keyword argument form, which -- I believe -- will let you pass your form class and have it used...

James Bennett
+3  A: 

EntryFormSet = modelformset_factory(Entry, form=EntryForm)

Harold
After setting it up as recommended above, passing entry_formset = EntryFormSet(prefix='entries') to render_to_response still displays all the fields. I'm still playing around with this.
Matt Hampel
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#controlling-which-fields-are-used-with-fields-and-exclude
Harold
Ah -- thanks. I expected it to inherit those from my EntryForm model, which also excluded some fields (which I left out from the example above for simplicity)
Matt Hampel