How to 'hide' all fields in a form based on a model class in django? There is the hidden widget which can be set on the form, but this solution makes me copy all fields from the model into the form.
Model._meta.get_all_field_names() gives you a list of the names which you can use to build the widget dictionary on a ModelForm.Meta:
class TestForm(forms.ModelForm):
class Meta:
model = Test
widgets = {field_name: forms.HiddenInput()
for field_name in Test._meta.get_all_field_names()}
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more