Search code examples
djangodjango-modelsdjango-viewshyperlinkdjango-admin

Django Admin: How to display more fields as links?


The default admin page for Django automatically makes the first heading of each table a link to edit the information (see below):

enter image description here

Clicking the ID column data will take you to a page to edit the fields in the selected table, in this case Applicants

Is there a way of changing this setup, so that Surname is the link to edit and not ID?

Many Thanks.


Solution

  • Use list_displays_links to control if and which fields in list_display should be linked to the edit page for an object.

    Example usage:

    class PersonAdmin(admin.ModelAdmin):
        list_display = ('first_name', 'surname', 'location')
        list_display_links = ('first_name', 'surname')
    

    ...would make both first_name and surname clickable.