0
0
Djangoframework~30 mins

Registering models in admin in Django - Mini Project: Build & Apply

Choose your learning style9 modes available
Registering models in admin
📖 Scenario: You are building a simple Django app to manage a library. You have created a model called Book to store book information.Now, you want to make the Book model manageable through the Django admin site so that librarians can add, edit, and delete books easily.
🎯 Goal: Register the Book model in the Django admin site so it appears in the admin interface.
📋 What You'll Learn
Create a Book model with fields title and author
Import the Book model into admin.py
Register the Book model with the Django admin site
💡 Why This Matters
🌍 Real World
Registering models in the Django admin site is a common task to allow non-technical users to manage data easily through a web interface.
💼 Career
Understanding how to register and customize models in the Django admin is essential for backend developers working with Django to build maintainable and user-friendly admin panels.
Progress0 / 4 steps
1
Create the Book model
Create a Django model called Book in models.py with two fields: title as a CharField with max length 100, and author as a CharField with max length 50.
Django
Need a hint?

Remember to import models from django.db before defining the model.

2
Import the Book model in admin.py
In admin.py, import the Book model from the current app's models module using from .models import Book.
Django
Need a hint?

Use a relative import to bring the Book model into admin.py.

3
Register the Book model with admin site
Register the Book model with the Django admin site by calling admin.site.register(Book) in admin.py.
Django
Need a hint?

Use admin.site.register() function to make the model manageable in the admin interface.

4
Verify admin registration
Ensure the admin.py file contains the import of Book and the registration line admin.site.register(Book) so the model appears in the admin site.
Django
Need a hint?

Double-check that both the import and registration lines are present in admin.py.