Django·Django from project to API

The Django admin

Register models and turn the admin into a useful internal tool.

Intermediate 12 min read Lesson 5 of 300 Challenge included
What you will be able to do
  • Register models in admin.py.
  • Use list_display and list_filter.
  • Add search_fields for quick lookup.
  • Restrict admin access to staff users.

In plain English

The admin is a production-quality internal interface generated from your models. Register models with list displays, filters and search so staff can work without custom screens. It is not the public UI.

admin.pyPython
from django.contrib import admin
from .models import Course, Lesson

@admin.register(Course)
class CourseAdmin(admin.ModelAdmin):
    list_display = ('title', 'slug', 'created_at')
    search_fields = ('title', 'slug')

@admin.register(Lesson)
class LessonAdmin(admin.ModelAdmin):
    list_display = ('title', 'course', 'minutes', 'published')
    list_filter = ('published', 'course')
Your turn

Add a search field

Easy

Make the admin search lessons by title.

PYTHON · starter
search_fields = ()
Check your understanding before moving on.
Knowledge checkQuestion 1

What is the Django admin best used for?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Forms and validation
Lesson 5 of 300 · 0% of course