Opened 4 years ago
Closed 4 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
fieldsandform_classis not permitted andfieldsare not checked whenform_classis specified, see get_form_class(). I'm not sure how you could reach this path withform_class🤔