list_display controls the columns shown for each object on a Django Admin listing page. Give it an iterable, usually a tuple, containing model field names, argument-less model methods, or callables on the ModelAdmin class. Each callable supplies the value displayed in its column. section 5.2
Show a musician’s birth weekday
In RiffMates, this configuration replaces the default object display with an ID, surname, and computed weekday:\n\nclass MusicianAdmin(admin.ModelAdmin):\n list_display = ('id', 'last_name', 'show_weekday')\n\n def show_weekday(self, obj):\n return obj.birth.strftime("%A")\n\n show_weekday.short_description = "Birth Weekday"\n\nDjango uses the first two names as Musician fields, calls show_weekday once per row, and uses its return value for the custom column. The method belongs on MusicianAdmin when the display feature is only needed in the Admin. section 5.2
Listing 5.2 Customized MusicianAdmin class with three columns
# RiffMates/bands/admin.py
from django.contrib import admin
from bands.models import Musician
@admin.register(Musician)
class MusicianAdmin(admin.ModelAdmin):
list_display = ('id', 'last_name', 'show_weekday') #1
def show_weekday(self, obj): #2
# Fetch weekday of artist’s birth
return obj.birth.strftime("%A") #3
show_weekday.short_description = "Birth Weekday" #4
Inspect the complete MusicianAdmin configuration, including the three-column tuple, row callable, formatted weekday, and custom heading. section 5.2
