Opened 13 years ago

Closed 12 years ago

#17911 closed Bug (fixed)

Admin change page does not "map" None choices when they are readonly

Reported by: justin.r.donnelly@… Owned by: edwtjo
Component: contrib.admin Version: 1.3
Severity: Normal Keywords:
Cc: charette.s@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: yes

Description

The Django admin change page does not "map" None values as per the class' model field choices when the values are readonly. It shows "(None)" (this value comes from EMPTY_CHANGELIST_VALUE) instead. This is demonstrated by the attached screenshot original_helpers_incorrect_change.png. The admin select page properly maps None values based on the class' model field choices. This is demonstrated by the attached screenshot original_helpers_correct_select.png. The change page should display the same value that the select page does. See attached screenshot modified_helpers_correct_change.png for what the admin change page should look like.

This is due to a bug in contrib/admin/helpers.py. The easiest way to fix the bug is to change line 185 of helpers.py from
result_repr = EMPTY_CHANGELIST_VALUE
to
result_repr = display_for_field(value, f)
However, that leaves the if and else branches executing the same statement (kind of weird). I have attached a modified version of helpers.py where that if/elif/else has been rewritten as an if/else.

I have also attached a tarball of an application that demonstrates this bug. The username is "user" and password is "password".

This is my first ticket submission, so I hope I provided everything you need.

Attachments (6)

mysite.tar (70.0 KB ) - added by justin.r.donnelly@… 13 years ago.
tarball of project that demonstrates bug
helpers.py (13.0 KB ) - added by justin.r.donnelly@… 13 years ago.
modified contrib/admin/helpers.py
original_helpers_correct_select.png (43.3 KB ) - added by justin.r.donnelly@… 13 years ago.
Django admin select page with original helpers.py file (correct)
original_helpers_correct_select.2.png (43.3 KB ) - added by justin.r.donnelly@… 13 years ago.
Django admin change page with original helpers.py file (incorrect)
modified_helpers_correct_change.png (44.5 KB ) - added by justin.r.donnelly@… 13 years ago.
Django admin change page with modified helpers.py file (correct)
helpers_diff.txt (245 bytes ) - added by justin.r.donnelly@… 13 years ago.
diff of modified helpers.py file against trunk

Download all attachments as: .zip

Change History (15)

by justin.r.donnelly@…, 13 years ago

Attachment: mysite.tar added

tarball of project that demonstrates bug

by justin.r.donnelly@…, 13 years ago

Attachment: helpers.py added

modified contrib/admin/helpers.py

by justin.r.donnelly@…, 13 years ago

Django admin select page with original helpers.py file (correct)

by justin.r.donnelly@…, 13 years ago

Django admin change page with original helpers.py file (incorrect)

by justin.r.donnelly@…, 13 years ago

Django admin change page with modified helpers.py file (correct)

comment:1 by Simon Charette, 13 years ago

Cc: charette.s@… added
Has patch: unset

Can you provide a diff against trunk of helpers.py instead of the modified file? It's easier to review the changes this way.

by justin.r.donnelly@…, 13 years ago

Attachment: helpers_diff.txt added

diff of modified helpers.py file against trunk

comment:2 by Jannis Leidel, 13 years ago

Triage Stage: UnreviewedAccepted

comment:3 by edwtjo, 12 years ago

Has patch: set
Owner: changed from nobody to edwtjo
Status: newassigned

comment:5 by Jannis Leidel, 12 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Julien Phalip <jphalip@…>, 12 years ago

Resolution: fixed
Status: assignedclosed

In 29d59a879ea5b116cc31a2fd91be1f7562e487c2:

Fixed #17911 -- Ensure that admin readonly fields' display values are shown in change forms when the raw value is None.

comment:7 by Julien Phalip <jphalip@…>, 12 years ago

In 7c91b67cfaf4669df55a715e62d891faea796f20:

[1.5.x] Fixed #17911 -- Ensure that admin readonly fields' display values are shown in change forms when the raw value is None.
Backport of 29d59a879ea5b116

comment:8 by Anssi Kääriäinen, 12 years ago

Resolution: fixed
Status: closedreopened

The added test doesn't work on Oracle, see #19391.

comment:9 by Anssi Kääriäinen, 12 years ago

Resolution: fixed
Status: reopenedclosed

Sorry, didn't mean to reopen this one.

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