Build Web Applications•Reading lesson•Free
django admin
No account is required. Learn the material, try the examples, and mark it complete locally when you are ready to move on.
Tutorial 11 - Django Admin
Why this matters
A founder may need to manage application data without you building a complete custom dashboard.
Django Admin provides a ready-made interface for registered models.
1. Register a model
Suppose:
python
class Booking(models.Model):
name = models.CharField(max_length=100)
date = models.DateField()
In admin.py:
python
from django.contrib import admin
from .models import Booking
admin.site.register(Booking)
The important line is:
python
admin.site.register(Booking)
You are telling Django:
Make this model available through the administration interface.
2. Create a superuser
bash
python manage.py createsuperuser
Django asks for a username, email, and password.
When typing the password, the terminal does not show characters. That is normal.
3. Open Admin
bash
python manage.py runserver
text
http://127.0.0.1:8000/admin/
Your registered models should appear.
4. Where is the booking actually stored?
The admin is not the database.
The database stores the record.
text
Customer-facing application
↓
Database
↑
Admin
Both interfaces work with the same underlying data.
5. Why this is useful for an MWP
Imagine your application is a booking website.
text
/services/
/book/
/contact/
text
Bookings
Customers
Services
You can therefore create a useful internal workflow without first building a custom dashboard.
6. Admin is not the public application
text
/
/booking/
/products/
Admin is primarily for trusted administrators.
7. Customizing the list
python
@admin.register(Booking)
class BookingAdmin(admin.ModelAdmin):
list_display = (
"name",
"date",
)
python
list_filter
search_fields
ordering
These are conveniences for managing data.
Learn them when a project needs them.
8. Admin and permissions
Django supports users and permissions.
Not every user should necessarily be able to edit every record.
This becomes more important when authentication and authorization are introduced.
9. Exercise
- register
Booking - create a superuser
- start Django
- open
/admin/ - create a booking through the public site
- find it in Admin
- edit it in Admin
- refresh the public application
You should observe the same database record from two interfaces.
10. Using ChatGPT
I registered my Booking model in Django Admin. Explain why it appears there and how the model, admin, and database are connected.
Show me how to make the booking list easier for an administrator to search, explaining each option before adding it.
Remember
text
Database
↑ ↑
│ │
Application Admin
One database can support multiple interfaces.
Finished this lesson?
Completion is saved in this browser without creating an account.