In a Django ModelForm, you can change the widget type of a field like so:
在Django ModelForm中,您可以更改字段的窗口小部件类型,如下所示:
class EntryForm(ModelForm):
entity = forms.CharField()
class Meta:
model = Entry
I can easily create a modelformset from the same model like so:
我可以轻松地从同一个模型创建一个modelformset,如下所示:
EntryFormSet = modelformset_factory(Entry)
But is there a way to include the input field type change change when creating a modelformset?
但有没有办法在创建modelformset时包含输入字段类型更改?
2 个解决方案
#1
13
EntryFormSet = modelformset_factory(Entry, form=EntryForm)
EntryFormSet = modelformset_factory(Entry,form = EntryForm)
#2
4
modelformset_factory
takes a keyword argument form
, which -- I believe -- will let you pass your form class and have it used...
modelformset_factory采用关键字参数形式,我相信它会让你传递你的表单类并使用它...
#1
13
EntryFormSet = modelformset_factory(Entry, form=EntryForm)
EntryFormSet = modelformset_factory(Entry,form = EntryForm)
#2
4
modelformset_factory
takes a keyword argument form
, which -- I believe -- will let you pass your form class and have it used...
modelformset_factory采用关键字参数形式,我相信它会让你传递你的表单类并使用它...