Episode 9 of 32
The Django Admin
Enable and use the built-in Django admin panel — register your models, create a superuser, and manage articles through the browser.
The Django Admin
Django comes with a built-in admin panel — a fully functional interface for managing your database records. You do not need to build your own admin dashboard.
Creating a Superuser
python manage.py createsuperuser
# You will be prompted for:
# Username: admin
# Email: admin@example.com
# Password: ********
Registering Models
# articles/admin.py
from django.contrib import admin
from .models import Article
admin.site.register(Article)
Registering a model makes it appear in the admin panel where you can create, read, update, and delete records.
Accessing the Admin
- Start the server:
python manage.py runserver - Go to
http://127.0.0.1:8000/admin/ - Log in with your superuser credentials
- You should see the Articles model listed
Customizing the Admin
# articles/admin.py
class ArticleAdmin(admin.ModelAdmin):
list_display = ('title', 'slug', 'date', 'author')
list_filter = ('date', 'author')
search_fields = ('title', 'body')
prepopulated_fields = {'slug': ('title',)}
admin.site.register(Article, ArticleAdmin)
Admin Customization Options
| Option | Purpose |
|---|---|
list_display | Columns shown in the list view |
list_filter | Filter sidebar |
search_fields | Search bar functionality |
prepopulated_fields | Auto-fill slug from title |
Key Takeaways
- The admin panel is built-in — just register your models
- Create a superuser with
python manage.py createsuperuser admin.site.register(Model)adds a model to the admin- Customize the admin with
ModelAdminclasses for better usability