0
0
Djangoframework~10 mins

List display configuration in Django - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - List display configuration
Define ModelAdmin class
Set list_display attribute
Register ModelAdmin with admin site
Open Django Admin page
Admin shows list with specified columns
User views/edit entries with configured columns
This flow shows how to configure which fields appear as columns in Django admin list view by setting list_display in a ModelAdmin class.
Execution Sample
Django
from django.contrib import admin
from .models import Book

class BookAdmin(admin.ModelAdmin):
    list_display = ('title', 'author', 'published_date')

admin.site.register(Book, BookAdmin)
This code sets up the Django admin to show the title, author, and published date columns for Book entries.
Execution Table
StepActionEvaluationResult
1Define BookAdmin class with list_displaylist_display = ('title', 'author', 'published_date')BookAdmin ready with columns configured
2Register BookAdmin with admin.siteadmin.site.register(Book, BookAdmin)Admin site knows to use BookAdmin for Book
3Open Django admin page for BookAdmin loads Book list viewColumns shown: title, author, published_date
4User views listAdmin renders rows with specified columnsList shows Book entries with those fields
5User clicks on a rowAdmin opens detail pageDetail page for selected Book opens
6ExitNo more actionsEnd of list display configuration execution
💡 User finishes viewing or editing; list display setup completed
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
list_displayundefined('title', 'author', 'published_date')('title', 'author', 'published_date')('title', 'author', 'published_date')('title', 'author', 'published_date')
BookAdmin registeredFalseFalseTrueTrueTrue
Admin page columnsNoneNoneNone['title', 'author', 'published_date']['title', 'author', 'published_date']
Key Moments - 3 Insights
Why do we need to define a ModelAdmin class instead of just registering the model?
The ModelAdmin class lets us customize admin behavior like which columns show. The execution_table step 1 shows setting list_display inside BookAdmin, which controls the columns.
What happens if list_display is not set?
If list_display is missing, Django shows only the model's __str__ representation as a single column. Step 3 in execution_table shows columns appear only after list_display is set.
Can list_display include methods or properties?
Yes, list_display can include model methods or properties that return values. They appear as columns too, as long as they are defined and accessible.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, which columns appear in the admin list view?
AAll model fields
Btitle, author, published_date
COnly title
DNo columns shown
💡 Hint
Check the 'Result' column in step 3 of the execution_table
At which step is the BookAdmin class registered with the admin site?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at the 'Action' column for registration in the execution_table
If you remove list_display from BookAdmin, what changes in the admin list view?
AOnly the model's string representation shows as one column
BColumns show all model fields
CAdmin list view breaks and shows error
DColumns show as empty
💡 Hint
Refer to key_moments answer about default behavior without list_display
Concept Snapshot
Django admin list_display config:
- Define ModelAdmin class
- Set list_display tuple with field names
- Register ModelAdmin with admin.site
- Admin list shows specified columns
- Allows customizing admin list view easily
Full Transcript
In Django, to control which columns appear in the admin list view for a model, you create a ModelAdmin class and set its list_display attribute to a tuple of field names. Then you register this ModelAdmin with the admin site. When you open the admin page for that model, the list view shows the columns you specified. Without list_display, only the model's string representation shows as a single column. This setup helps you customize the admin interface to show important fields at a glance.