Opened 9 years ago

Closed 9 years ago

#26582 closed Cleanup/optimization (fixed)

Better ArrayField/list formatting in the admin

Reported by: Dan Watson Owned by: nobody
Component: contrib.admin Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When specifying an ArrayField in list_display or readonly_fields, the admin shows a rather ugly python representation of the list, e.g.:

[u'Value 1', u'Value 2', u'Value 3']

A simple solution would be to check for isinstance(value, (list, tuple)) in django.contrib.admin.utils.display_for_value and return a comma- or semicolon-separated display string, then change django.contrib.admin.utils.display_for_field to call display_for_value at the end instead of just smart_text. This would be pretty un-intrusive, and work for any fields providing list type values.

A more thorough solution might involve some mechanism by which fields or ModelAdmin instances can customize the display formatting of field values. Or maybe even some sort of template-based rendering solution in line with https://github.com/django/django/pull/6498.

Change History (4)

comment:2 by Tim Graham, 9 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:3 by Dan Watson, 9 years ago

Needs tests: unset

Added tests to the PR.

comment:4 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In ad403ffa:

Fixed #26582 -- Added prettier admin display for list values.

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