#2301 closed enhancement (fixed)
[patch] AdminOption property to set links on display_field fields
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.admin | Version: | |
Severity: | minor | Keywords: | list_display link |
Cc: | kilian.cavalotti@… | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The attached patch add the ability to specify for which fields (among those listed in display_fields
) the admin interface will present a link to the related object edit page.
Currently, only the first field listed in display_fields
get a <a href="obj_id/">
tag. For example, if you have blank=True
in your model for the first field, you won't be able to edit objects for which this field has been left blank. Moreover, you may want the admin interface to present links on several fields, or on an other field than the first one.
This patch add a display_fields_links
property to the AdminOption class, with the following constraints:
display_fields_links
needsdisplay_fields
to be defined,- fields specified in
display_fields_links
need to be present indisplay_fields
, - if
display_fields_links
is omitted, the first of thedisplay_fields
fields will still be used for links.
Since a picture is better than long sentences, an example is attached.
Attachments (3)
Change History (8)
by , 18 years ago
Attachment: | display_fields_links.png added |
---|
by , 18 years ago
Attachment: | django.admin.list_display_links.patch added |
---|
Patch adding display_fields_links option
comment:1 by , 18 years ago
Simplified models.py
used to create the attached screenshot:
class Host(models.Model): hostname = models.CharField(maxlength = 63, unique = True, blank = True, null = True) type = models.ForeignKey(Type) ip = models.ForeignKey(IP) mac = models.CharField(maxlength = 17, unique = True, db_index = True) subnet = models.ForeignKey(Subnet) vlan = models.ForeignKey(Vlan) class Admin: list_display = ('hostname', 'type', 'mac', 'ip', 'subnet', 'vlan') list_display_links = ('mac', 'hostname')
comment:2 by , 18 years ago
Status: | new → assigned |
---|
comment:3 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:4 by , 18 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I just remarked a light CSS problem with list_display_links
. If several fields are listed in list_display_links
, they all will be displayed as HTML <th>
, even when not in first place. Only the first column should be tagged as <th>
, the following ones should be <td>
.
Attached patch allow to displays subsequent link columns as <td>
.
by , 18 years ago
Attachment: | list_display_links.th.patch added |
---|
Patch to display non-first link columns as <td>
Screenshot of admin interface with two fields used for linking to edit pages