要将ModelField中的字段设为隐藏字段,请使用HiddenInput小部件。ModelForm对所有字段都使用了明智的默认小部件,你只需要在构造对象时覆盖它即可。
class TagStatusForm(forms.ModelForm): class meta: model = TagStatus widgets = {'tag': forms.HiddenInput()}
要将ModelField中的字段设为隐藏字段,请使用HiddenInput小部件。ModelForm对所有字段都使用了明智的默认小部件,你只需要在构造对象时覆盖它即可。
class TagStatusForm(forms.ModelForm): class meta: model = TagStatus widgets = {'tag': forms.HiddenInput()}