Opened 18 years ago

Closed 18 years ago

Last modified 17 years ago

#2301 closed enhancement (fixed)

[patch] AdminOption property to set links on display_field fields

Reported by: kilian <kilian.cavalotti@…> 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 needs display_fields to be defined,
  • fields specified in display_fields_links need to be present in display_fields,
  • if display_fields_links is omitted, the first of the display_fields fields will still be used for links.

Since a picture is better than long sentences, an example is attached.

Attachments (3)

display_fields_links.png (20.1 KB ) - added by kilian <kilian.cavalotti@…> 18 years ago.
Screenshot of admin interface with two fields used for linking to edit pages
django.admin.list_display_links.patch (3.3 KB ) - added by kilian <kilian.cavalotti@…> 18 years ago.
Patch adding display_fields_links option
list_display_links.th.patch (1.3 KB ) - added by kilian <kilian.cavalotti@…> 18 years ago.
Patch to display non-first link columns as <td>

Download all attachments as: .zip

Change History (8)

by kilian <kilian.cavalotti@…>, 18 years ago

Attachment: display_fields_links.png added

Screenshot of admin interface with two fields used for linking to edit pages

by kilian <kilian.cavalotti@…>, 18 years ago

Patch adding display_fields_links option

comment:1 by kilian <kilian.cavalotti@…>, 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 Adrian Holovaty, 18 years ago

Status: newassigned

comment:3 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: assignedclosed

(In [3307]) Fixed #2301 -- Added list_display_links option to 'class Admin', which regulates which fields in the change list have links. Thanks, kilian

comment:4 by kilian <kilian.cavalotti@…>, 18 years ago

Resolution: fixed
Status: closedreopened

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 kilian <kilian.cavalotti@…>, 18 years ago

Attachment: list_display_links.th.patch added

Patch to display non-first link columns as <td>

comment:5 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: reopenedclosed

Fixed in [3333].

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