What is "list_display_links" for Django Admin?

1.8k Views Asked by At

I have Person model below:

# "store/models.py"

from django.db import models

class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    age =  models.IntegerField()
    
    def __str__(self):
        return self.first_name + " " + self.last_name

Then, I assigned "first_name", "last_name" and "age" to list_display in Person admin as shown below:

# "store/admin.py"

from django.contrib import admin
from .models import Person

@admin.register(Person)
class PersonAdmin(admin.ModelAdmin):
    list_display = ("first_name", "last_name", "age") # Here

Now, FIRST NAME, LAST NAME and AGE are displayed as shown below:

enter image description here

Next, I assigned "first_name", "last_name" and "age" to list_display_links in Person admin as shown below:

# "store/admin.py"

from django.contrib import admin
from .models import Person

@admin.register(Person)
class PersonAdmin(admin.ModelAdmin):
    list_display = ("first_name", "last_name", "age")
    list_display_links = ("first_name", "last_name", "age") # Here

But, nothing happened to the "change list" page as shown below:

enter image description here

So, what is list_display_links?

1

There are 1 best solutions below

0
Super Kai - Kazuya Ito On

Actually, the values of LAST NAME and AGE become the links to the "change" page in addition to the values of FIRST NAME as shown below. *By default, the values of the first column "FIRST NAME" displayed are the links to the "change" page:

enter image description here

So, you can go to the "change" page by clicking on Smith as shown below:

enter image description here

The documentation explains about list_display_links below:

Use list_display_links to control if and which fields in list_display should be linked to the "change" page for an object.

By default, the change list page will link the first column – the first field specified in list_display ...