Django Lesson 7: Admin Panel
Django’s built-in admin panel lets you manage all your data without writing a single line of admin UI code. It’s incredibly powerful.
Setup
# Create admin superuser
python manage.py createsuperuser
# Enter: username, email, password
# Visit: http://127.0.0.1:8000/admin
# Login with your superuser credentials
Register Models
# posts/admin.py
from django.contrib import admin
from .models import Post, Category
# Basic registration
admin.site.register(Category)
# Advanced registration with customization
@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
list_display = ["title", "author", "status", "created_at"]
list_filter = ["status", "created_at", "author"]
search_fields = ["title", "content"]
prepopulated_fields = {"slug": ("title",)} # auto-fill slug from title
raw_id_fields = ["author"] # better than dropdown for large tables
date_hierarchy = "created_at"
ordering = ["-created_at"]
# Inline editing
# inlines = [CommentInline]
🏋️ Practice Task
Register your Task and Project models in admin. Customize TaskAdmin: show title, project, priority, due_date, done in list. Add filters for priority and done. Add search on title. Add prepopulated slug if you have one. Create 5 tasks via admin.
💡 Hint: @admin.register(Task) class TaskAdmin(admin.ModelAdmin): list_display = [“title”,”project”,”priority”,”done”,”due_date”]