[Django] #33074: Do not require fields on UpdateView/CreateView if form specified

4 views
Skip to first unread message

Django

unread,
Aug 30, 2021, 4:14:39 PM8/30/21
to django-...@googlegroups.com
#33074: Do not require fields on UpdateView/CreateView if form specified
-------------------------------------+-------------------------------------
Reporter: Dan Swain | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Generic | Version: 3.2
views | Keywords: CreateView
Severity: Normal | UpdateView form ModelFormMixin
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/33074>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 31, 2021, 1:10:01 AM8/31/21
to django-...@googlegroups.com
#33074: Do not require fields on UpdateView/CreateView if form specified
-------------------------------------+-------------------------------------
Reporter: Dan Swain | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Generic views | Version: 3.2
Severity: Normal | Resolution: invalid
Keywords: CreateView | Triage Stage:
UpdateView form ModelFormMixin | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

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
[https://github.com/django/django/blob/3219dd3388c437b4bd869b76ddd43c9cdad05090/django/views/generic/edit.py#L76-L99
get_form_class()]. I'm not sure how you could reach this path with
`form_class` 🤔

--
Ticket URL: <https://code.djangoproject.com/ticket/33074#comment:1>

Reply all
Reply to author
Forward
0 new messages