Matt Hampel
Matt Hampel

Reputation: 5237

Changing field type in a Django ModelFormset

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?

Upvotes: 5

Views: 2594

Answers (2)

Harold
Harold

Reputation: 5325

EntryFormSet = modelformset_factory(Entry, form=EntryForm)

Upvotes: 13

James Bennett
James Bennett

Reputation: 11163

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

Upvotes: 4

Related Questions