Code

Opened 6 years ago

Closed 6 years ago

#7724 closed (invalid)

get_FIELD_display in backend doesn't respect FIELD's name or verbose_name

Reported by: CaptainCapacitor Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: admin, get_FIELD_*, name, verbose name
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

colour_choices = [(0, 'red'), (1, 'blue'), (2, 'green')]

class Car(models.Model):
    ...
    colour = models.IntegerField(name='colour', verbose_name='Primary Colour', choices=colour_choices)
    ...

    class Admin:
        list_display=['name', 'year', 'make', 'model', 'get_colour_display']

In the Admin panel, the final field is titled "Get Colour Display", and no amount of effort can convince it otherwise.

Attachments (0)

Change History (1)

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

There's nothing to suggest it should behave like this. You're hoping it might, but it isn't really worth the extra code when there's already a way to set the title. When you use a function in the list_display list it uses the short_description attribute on the function for the title, otherwise a reasonable default is used. This is documented and the versions of get_FIELD_display() created automatically are no different int his respect.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.