Customizing the Django admin panel
The Django admin panel is a powerful built-in feature of Django that automatically generates a user-friendly interface to manage our application’s data models. This is a great feature of Django that many other frameworks don’t offer.
Figure 7.3 shows the current movies admin page.
Figure 7.3 – The movies admin page
The admin panel may seem very rigid, but fortunately, Django allows us to customize it according to our needs. Let’s apply two customizations to the movies admin page – first, ordering movies by name, and second, allowing searches by name.
Ordering movies by name
In /movies/admin.py
, add the following in bold:
from django.contrib import admin from .models import Movie class MovieAdmin(admin.ModelAdmin): ordering = ['name'] admin.site.register(Movie, MovieAdmin)
Let’s explain the previous code:
- We created a
MovieAdmin...