Admin change page does not "map" None choices when they are readonly
|Reported by:||justin.r.donnelly@…||Owned by:||edwtjo|
|Cc:||charette.s@…||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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
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.
Change History (15)
comment:1 Changed 3 years ago by charettes
- Cc charette.s@… added
- Has patch unset
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:3 Changed 3 years ago by edwtjo
- Has patch set
- Owner changed from nobody to edwtjo
- Status changed from new to assigned
comment:6 Changed 3 years ago by Julien Phalip <jphalip@…>
- Resolution set to fixed
- Status changed from assigned to closed
comment:8 Changed 3 years ago by akaariai
- Resolution fixed deleted
- Status changed from closed to reopened