Opened 15 years ago

Closed 14 years ago

Last modified 13 years ago

#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)

12475_changelist_hidden_fields.diff (5.0 KB ) - added by Julien Phalip 14 years ago.
12475_changelist_hidden_fields.2.diff (6.4 KB ) - added by Julien Phalip 14 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 by szczav, 15 years ago

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 :)

comment:2 by Russell Keith-Magee, 15 years ago

Resolution: invalid
Status: newclosed

comment:3 by master, 14 years ago

Resolution: invalid
Status: closedreopened
Summary: Confusion between list_display and list_display_link for 'id' fieldConfusion between list_display and list_display_links for 'id' field
Version: 1.11.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 Karen Tracey, 14 years ago

Resolution: worksforme
Status: reopenedclosed

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 master, 14 years ago

Resolution: worksforme
Status: closedreopened

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 Karen Tracey, 14 years ago

Triage Stage: UnreviewedAccepted
Version: 1.2-beta1.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:7 by Karen Tracey, 14 years ago

#13825 reported this again.

comment:8 by Julien Phalip, 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 Julien Phalip, 14 years ago

comment:9 by Simon Meers, 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 Julien Phalip, 14 years ago

comment:10 by Julien Phalip, 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 Simon Meers, 14 years ago

Triage Stage: AcceptedReady for checkin

That looks better, thanks Julien.

comment:12 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: reopenedclosed

In [15722]:

Fixed #12475 -- Fixed an edge case with hidden fields in ModelAdmin changelists when used in conjunction with list_display_links or list_editable. Thanks, Simon Meers, Julien Phalip, Karen and master.

comment:13 by Jannis Leidel, 14 years ago

In [15724]:

[1.2.X] Fixed #12475 -- Fixed an edge case with hidden fields in ModelAdmin changelists when used in conjunction with list_display_links or list_editable. Thanks, Simon Meers, Julien Phalip, Karen and master.

Backport from trunk (r15722).

comment:14 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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