Opened 3 years ago
Closed 3 years ago
#33074 closed Cleanup/optimization (invalid)
Do not require fields on UpdateView/CreateView if form specified
Reported by: | Dan Swain | Owned by: | nobody |
---|---|---|---|
Component: | Generic views | Version: | 3.2 |
Severity: | Normal | Keywords: | CreateView UpdateView form ModelFormMixin |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When a form class is specified on CreateView or UpdateView, then even though the fields are specified on the form, the following error occurs:
django.core.exceptions.ImproperlyConfigured: Using ModelFormMixin (base class of MyModelCreateView) without the 'fields' attribute is prohibited.
It seems like fields should not have to be specified on a CreateView or UpdateView when a form is specified since fields HAVE to be specified on a form. Why can't the view just use the fields specified on the form? Raising this error when no fields have been specified on the view but a form HAS been specified seems to go against DRY.
Thanks for the report, however specifying both
fields
andform_class
is not permitted andfields
are not checked whenform_class
is specified, see get_form_class(). I'm not sure how you could reach this path withform_class
🤔