Django

Code

Ticket #2301 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

[patch] AdminOption property to set links on display_field fields

Reported by: kilian <kilian.cavalotti@lip6.fr> Assigned to: adrian
Milestone: Component: django.contrib.admin
Version: Keywords: list_display link
Cc: kilian.cavalotti@lip6.fr Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

display_fields_links.png (20.1 kB) - added by kilian <kilian.cavalotti@lip6.fr> on 07/06/06 08:29:46.
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@lip6.fr> on 07/06/06 08:30:58.
Patch adding display_fields_links option
list_display_links.th.patch (1.3 kB) - added by kilian <kilian.cavalotti@lip6.fr> on 07/11/06 07:39:37.
Patch to display non-first link columns as <td>

Change History

07/06/06 08:29:46 changed by kilian <kilian.cavalotti@lip6.fr>

  • attachment display_fields_links.png added.

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

07/06/06 08:30:58 changed by kilian <kilian.cavalotti@lip6.fr>

  • attachment django.admin.list_display_links.patch added.

Patch adding display_fields_links option

07/06/06 08:37:20 changed by kilian <kilian.cavalotti@lip6.fr>

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

07/09/06 21:38:18 changed by adrian

  • status changed from new to assigned.

07/09/06 23:16:26 changed by adrian

  • status changed from assigned to closed.
  • resolution set to fixed.

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

07/11/06 07:38:39 changed by kilian <kilian.cavalotti@lip6.fr>

  • status changed from closed to reopened.
  • resolution deleted.

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>.

07/11/06 07:39:37 changed by kilian <kilian.cavalotti@lip6.fr>

  • attachment list_display_links.th.patch added.

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

07/11/06 14:13:11 changed by adrian

  • status changed from reopened to closed.
  • resolution set to fixed.

Fixed in [3333].


Add/Change #2301 ([patch] AdminOption property to set links on display_field fields)




Change Properties
Action