How does the Django admin site work and how do you customize it?
Understand how the Django admin auto-generates CRUD screens from models and how to customize it with ModelAdmin, list_display, filters, and inlines.
Expected Interview Answer
The Django admin is an auto-generated, model-driven web interface for managing your application's data — it reads your registered models and their metadata to build create, read, update, and delete (CRUD) screens with no hand-written UI. You customize it by registering models with ModelAdmin classes that control list columns, filters, search, forms, permissions, and inline related objects.
When you register a model with admin.site.register or the @admin.register decorator, Django introspects the model's fields and builds list and change views automatically. A ModelAdmin subclass then fine-tunes behavior through attributes like list_display, list_filter, search_fields, ordering, readonly_fields, and inlines, plus overridable methods (get_queryset, save_model, has_delete_permission). The admin respects the auth framework, so what each staff user sees and can change is governed by per-model permissions.
- Instant CRUD interface generated from your models
- Powerful list filtering, search, and pagination out of the box
- Fine-grained customization via ModelAdmin without templates
- Inline editing of related objects on one page
- Built-in permission and staff-user access control
AI Mentor Explanation
The Django admin is like an automatic scoreboard operator that reads each team's official squad sheet and instantly builds the display — batting order, bowling figures, dismissals — without anyone wiring the board by hand. If you want the strike rate column shown or players filtered by role, you hand the operator a short instruction card (ModelAdmin) rather than rebuilding the whole scoreboard, so the interface adapts to exactly what the match needs.
Step-by-Step Explanation
Step 1
Create the model
Define your data model in models.py and run migrations so the table exists.
Step 2
Register with the admin
Use @admin.register(Model) or admin.site.register(Model) to expose it in the admin site.
Step 3
Add a ModelAdmin
Subclass admin.ModelAdmin to set list_display, list_filter, search_fields, and ordering.
Step 4
Configure forms and inlines
Use fields/fieldsets, readonly_fields, and inline classes to edit related objects together.
Step 5
Override behavior
Override methods like save_model, get_queryset, or permission hooks for custom logic.
Step 6
Control access
Grant staff status and per-model permissions so each user only sees allowed data.
What Interviewer Expects
- Understanding the admin is auto-generated from models
- Knowing ModelAdmin attributes like list_display and list_filter
- How to register models with the decorator or register call
- Awareness of inlines for related objects
- How permissions and staff status gate admin access
Common Mistakes
- Thinking the admin is meant as a public end-user UI
- Forgetting to register the model, so it never appears
- Confusing list_display (columns) with fields (form layout)
- Ignoring permissions and exposing sensitive data to all staff
- Editing generated templates instead of using ModelAdmin options
Best Answer (HR Friendly)
“The Django admin is a ready-made web dashboard that Django builds automatically from your data models, letting staff add, edit, and delete records without any custom screens. You tailor it by writing small configuration classes that decide which columns, filters, and search boxes appear.”
Code Example
from django.contrib import admin
from .models import Article, Comment
class CommentInline(admin.TabularInline):
model = Comment
extra = 1
@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
list_display = ('title', 'author', 'published', 'created_at')
list_filter = ('published', 'author')
search_fields = ('title', 'body')
ordering = ('-created_at',)
readonly_fields = ('created_at',)
inlines = [CommentInline]
def save_model(self, request, obj, form, change):
if not obj.author_id:
obj.author = request.user
super().save_model(request, obj, form, change)Follow-up Questions
- What is the difference between list_display and fields?
- How do inlines let you edit related models on one page?
- How do you restrict which staff users can edit a model?
- How would you add a custom admin action to bulk-update rows?
- When would you build a custom view instead of using the admin?
MCQ Practice
1. Which ModelAdmin attribute controls the columns shown in the list view?
list_display defines the columns rendered in the admin's change-list (table) view.
2. How do you register a model so it appears in the admin?
Registering with admin.site.register or the @admin.register decorator exposes the model in the admin site.
3. What is the purpose of an admin inline class?
TabularInline and StackedInline let you create and edit related child objects directly on the parent object's change form.
Flash Cards
What generates the Django admin screens? — Django introspects registered models and their fields to auto-build CRUD views.
What does list_filter do? — Adds sidebar filters on the change-list so staff can narrow rows by field values.
What is a ModelAdmin? — A class that customizes how a model behaves in the admin — columns, forms, filters, permissions.
What are inlines? — Classes that let you edit related objects on the parent record's change page.