Django Admin Site0%

Django Admin Site

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

Django Admin Site

One of Django's most celebrated "batteries-included" features is the Django Admin Site. It reads metadata from your models to automatically generate an enterprise-grade administrative dashboard for managing content, inspecting database records, and managing staff permissions. Customizing the admin site transforms it into a bespoke operations back-office.


1. Enabling the Admin and Creating a Superuser

Django Admin is enabled by default in INSTALLED_APPS via django.contrib.admin. To log in, generate an administrative superuser account:

Bash / Terminal
python manage.py createsuperuser
# Prompt: Username, Email, Password

Start the dev server and visit http://127.0.0.1:8000/admin/.


2. Registering Models with ModelAdmin

To expose your models in the admin, register them in admin.py:

Python
# articles/admin.py
from django.contrib import admin
from .models import Article, Category, Tag
 
# Simple registration:
admin.site.register(Category)
admin.site.register(Tag)
 
# Advanced customized registration:
@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
# 1. Columns displayed in the record list view
list_display = ("title", "author", "status", "category", "view_count", "created_at")
# 2. Clickable columns linking to the detail change form
list_display_links = ("title",)
# 3. Sidebar filtering widgets
list_filter = ("status", "category", "created_at", "is_featured")
# 4. Search bar querying specified fields
search_fields = ("title", "content", "author__username")
# 5. Automatically populate slug field based on title input in real-time
prepopulated_fields = {"slug": ("title",)}
# 6. Pagination count per page
list_per_page = 25
# 7. Form field groupings and layouts
fieldsets = (
("General Information", {
"fields": ("title", "slug", "author", "category")
}),
("Content Body", {
"fields": ("content",)
}),
("Publication Settings", {
"classes": ("collapse",), # Collapsible section
"fields": ("status", "is_featured", "tags")
}),
)

3. Custom Admin Actions

You can add bulk action triggers to the admin dropdown menu:

Python
@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
actions = ["make_published", "make_archived"]
 
@admin.action(description="Mark selected articles as Published")
def make_published(self, request, queryset):
updated_count = queryset.update(status="published")
self.message_user(
request,
f"Successfully marked {updated_count} articles as published."
)
 
@admin.action(description="Mark selected articles as Archived")
def make_archived(self, request, queryset):
queryset.update(status="archived")

When managing parent and child models (e.g. an Article and its Comments, or an Order and Line Items), TabularInline lets staff edit children directly inside the parent page:

Python
class CommentInline(admin.TabularInline):
model = Comment
extra = 1 # Number of empty blank rows to display
 
@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
inlines = [CommentInline]

Interactive Quiz

Practice Quiz

Question 1
What command creates an administrative user capable of logging into /admin/?
Question 2
What does the prepopulated_fields option do in ModelAdmin?
Question 3
How do you add searchable columns to the Django Admin change list?
Question 4
What is the purpose of admin.TabularInline?
Question 5
Why is list_filter = ("status", "category") useful on high-volume models?
Next Lesson

User Model & Permissions

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext