0
0
Djangoframework~30 mins

List display configuration in Django - Mini Project: Build & Apply

Choose your learning style9 modes available
List Display Configuration in Django Admin
📖 Scenario: You are building a Django web application to manage a bookstore. You want to customize the Django admin interface to show a list of books with specific details.
🎯 Goal: Configure the Django admin to display a list of books showing the title, author, and published_year columns.
📋 What You'll Learn
Create a Django model called Book with fields title, author, and published_year.
Create an admin class called BookAdmin.
Add a list_display attribute to BookAdmin with the fields title, author, and published_year.
Register the Book model with the BookAdmin class.
💡 Why This Matters
🌍 Real World
Customizing the Django admin list display helps administrators quickly see important information about data entries, improving management efficiency.
💼 Career
Knowing how to configure Django admin is essential for backend developers working with Django to build maintainable and user-friendly admin interfaces.
Progress0 / 4 steps
1
Create the Book model
Create a Django model called Book in models.py with these exact fields: title as a CharField with max length 100, author as a CharField with max length 50, and published_year as an IntegerField.
Django
Need a hint?

Use models.CharField for text fields and models.IntegerField for numbers.

2
Create the BookAdmin class
In admin.py, import admin and the Book model. Then create a class called BookAdmin that inherits from admin.ModelAdmin.
Django
Need a hint?

Remember to import admin and Book before defining BookAdmin.

3
Add list_display to BookAdmin
Add a list_display attribute to the BookAdmin class with the exact list: 'title', 'author', and 'published_year'.
Django
Need a hint?

Use a tuple with the field names as strings for list_display.

4
Register Book with BookAdmin
Register the Book model with the BookAdmin class using admin.site.register(Book, BookAdmin).
Django
Need a hint?

Use admin.site.register() with two arguments: the model and the admin class.