Opened 3 years ago
Closed 3 years ago
#33093 closed Uncategorized (invalid)
Overriding default fields overrides Meta labels
Reported by: | Abhijeet Viswa | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | yes |
Description
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.
It's documented in the "Note" box of 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."