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.

Change History (1)

comment:1 by Mariusz Felisiak, 3 years ago

Resolution: invalid
Status: newclosed

Thanks for the report, however specifying both fields and form_class is not permitted and fields are not checked when form_class is specified, see get_form_class(). I'm not sure how you could reach this path with form_class 🤔

Note: See TracTickets for help on using tickets.
Back to Top