[Django] #33093: Overriding default fields overrides Meta labels

4 views
Skip to first unread message

Django

unread,
Sep 8, 2021, 3:52:24 PM9/8/21
to django-...@googlegroups.com
#33093: Overriding default fields overrides Meta labels
------------------------------------------+------------------------
Reporter: Abhijeet Viswa | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 1 |
------------------------------------------+------------------------
Right of the bat, I'd like to say that I'm not sure if this is a proper
bug or not. It felt like a bug, and it took some time to figure out what
the issue was.

Here's a minimal example example:

{{{
class ExampleForm(forms.ModelForm):
name = forms.CharField()

class Meta:
model = ExampleModel
fields = ('name', )
labels = {
'name': 'Test Label',
}
}}}

`ExampleForm().fields['name'].label` is None because `label` is not passed
into the overriding field declaration. Ideally, the lack of a field
attribute should result in label declared in `Meta.labels` being used
instead of prettifying it using `capfirst`. Alternatively, this can be
added to the documentation.

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

Django

unread,
Sep 8, 2021, 6:06:21 PM9/8/21
to django-...@googlegroups.com
#33093: Overriding default fields overrides Meta labels
--------------------------------+--------------------------------------

Reporter: Abhijeet Viswa | Owner: nobody
Type: Uncategorized | Status: closed
Component: Forms | Version: dev
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
--------------------------------+--------------------------------------
Changes (by Tim Graham):

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


Comment:

It's documented in the "Note" box of
[https://docs.djangoproject.com/en/stable/topics/forms/modelforms
/#overriding-the-default-fields this section]: "Fields defined
declaratively are left as-is, therefore any customizations made to Meta
attributes such as widgets, labels, help_texts, or error_messages are
ignored; these only apply to fields that are generated automatically."

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

Reply all
Reply to author
Forward
0 new messages