Opened 6 years ago

Closed 6 years ago

#9746 closed (invalid)

Using a custom widget for a item in ModelForm should use the model verbose_name?

Reported by: waltercruz Owned by: nobody
Component: Forms Version: 1.0
Severity: Keywords: forms, model, verbose name, label
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi all! To simplify my question, I will use a sample code from the docs: http://docs.djangoproject.com/en/dev/topics/forms/modelforms/?from=olddocs#a-full-example.

Say, by example, that I have added verbose names to the three fields, name as "Full Name", title as "Honor Title" and birth_date as "Birthday". Using a custom widget on a model form (like the sample, widget=forms.Select(choices=TITLE_CHOICES) to the title field) will make my form don't use the verbose name from the modelas the label. To add the correct label, I've to add a label='Something'. I expected that the generated model would use the verbose names from the model, even if I override some widget. Am I right in my expectation?

Change History (2)

comment:1 Changed 6 years ago by waltercruz

  • Component changed from Uncategorized to Forms
  • Keywords forms model verbose name label added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by brosner

  • Resolution set to invalid
  • Status changed from new to closed

This is documented behavior. http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-field-types. You either just have to re-specify it or override the ModelForm's __init__ and pop the widget it through self.fields.

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