Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#2301 closed enhancement (fixed)

[patch] AdminOption property to set links on display_field fields

Reported by: kilian <kilian.cavalotti@…> Owned by: adrian
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: UI/UX:

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@…> 8 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@…> 8 years ago.
Patch adding display_fields_links option
list_display_links.th.patch (1.3 KB) - added by kilian <kilian.cavalotti@…> 8 years ago.
Patch to display non-first link columns as <td>

Download all attachments as: .zip

Change History (8)

Changed 8 years ago by kilian <kilian.cavalotti@…>

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

Changed 8 years ago by kilian <kilian.cavalotti@…>

Patch adding display_fields_links option

comment:1 Changed 8 years ago by kilian <kilian.cavalotti@…>

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 Changed 8 years ago by adrian

  • Status changed from new to assigned

comment:3 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from assigned to closed

(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 Changed 8 years ago by kilian <kilian.cavalotti@…>

  • Resolution fixed deleted
  • Status changed from closed to 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>.

Changed 8 years ago by kilian <kilian.cavalotti@…>

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

comment:5 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to closed

Fixed in [3333].

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.