#12475 closed (fixed)
Confusion between list_display and list_display_links for 'id' field
Reported by: | master | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.1 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In a ModelAdmin class, define list_display with 'id' and some other fields.
If 'id' is the first field, define list_display_link with some fields but without 'id',
otherwise you can omit list_display_link.
Problem : The 'id' column is rendered as a second hidden <input> (the 'correct' hidden input is still at the end of the <tr>) and the value is not shown.
Workaround : To have a correct screen when 'id' is in list_display, it has to be in list_display_link as well (either explicity or when a default list_display_link takes it as the first field of list_display).
Attachments (2)
Change History (16)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 15 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Summary: | Confusion between list_display and list_display_link for 'id' field → Confusion between list_display and list_display_links for 'id' field |
Version: | 1.1 → 1.2-beta |
szczav: where did you find such a "list_display_link" function ? It was only a typo.
Please read "list_display_links" in my description.
Note: Problem was detected on v1.1, and can still be reproduced on v1.2 beta 1.
comment:4 by , 15 years ago
Resolution: | → worksforme |
---|---|
Status: | reopened → closed |
I cannot recreate any problem with id
being include in list_display
and list_display_links
, on r13253. Given this model:
class TestModel(models.Model): name = models.CharField(max_length=40) birthdate = models.DateField(null=True, blank=True) birthtime = models.TimeField(null=True, blank=True)
The following model admin definition produces a correct change list page for TestModel
:
class TMAdmin(admin.ModelAdmin): list_display = ('id', 'name', 'birthdate', 'birthtime') list_display_links = ('name',)
The ID for the model is shown, but is not a link to the change page for the instance; the name field is shown and is a link to the change page, the other two fields are displayed but not links.
If I include id
in list_display_links
that works as well (the id
value then also becomes a link to the change page), and if I omit list_display_links
entirely then everything is still fine: in that case the id
value is the one and only link to the change page for the instance.
If you continue to see a problem on current code, please be more specific about your model and model admin definitions: given the current description I cannot find any problem.
comment:5 by , 15 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
I confirm that your demo classes don't show the problem. I discovered that they will (for me, r13265) with an editable field (anyone valid, i.e. in list_display and not in list_display_links):
list_editable = ('birthtime',)
comment:6 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.2-beta → 1.1 |
OK, problem exists if you have the model admin specified like so, for example:
class TMAdmin(admin.ModelAdmin): list_display = ('id', 'name', 'birthdate', 'birthtime') list_display_links = ('name',) list_editable = ('birthtime', )
And the nature of the problem is that while there is a column shown for ID values, nothing appears in it.
Testing shows this problem has existed as far back as 1.1; it was not introduced in the 1.2 cycle.
comment:8 by , 14 years ago
Has patch: | set |
---|---|
milestone: | → 1.3 |
Thanks Karen and master for narrowing down the test case. In fact the issue is that if there is a form (i.e. list_editable
is activated) and the form contains some hidden fields (in this case 'id') and those fields are not in list_editable
or in list_display_links
, then the hidden fields are displayed in the table cell instead of its human-readable value. The attached patch fixes this problem by never showing hidden fields in the table, since those fields are already taken care of separately in <div class="hiddenfields">
anyway.
by , 14 years ago
Attachment: | 12475_changelist_hidden_fields.diff added |
---|
comment:9 by , 14 years ago
I'm not sure how robust this solution is; from my skimming of the code, it appears that result_hidden_fields
only adds hidden fields for the model's primary key; if we remove all hidden fields from the table, does this mean that non-pk hidden fields (if such things are possible in list-editing?) will disappear altogether?
by , 14 years ago
Attachment: | 12475_changelist_hidden_fields.2.diff added |
---|
comment:10 by , 14 years ago
Thank you Simon. You're right, result_hidden_fields
only deals with the primary keys. Other non-pk hidden fields are "displayed" normally in the changelist table. I have amended the patch and the tests to reflect that.
comment:11 by , 14 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
That looks better, thanks Julien.
I presume that this strange behaviour is caused by the fact that you have used "list_display_link" instead of "list_display_links" ('s' at the end). It is no bug, but small oversight :)