← Back to all tutorials

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

  1. Start the server: python manage.py runserver
  2. Go to http://127.0.0.1:8000/admin/
  3. Log in with your superuser credentials
  4. 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

OptionPurpose
list_displayColumns shown in the list view
list_filterFilter sidebar
search_fieldsSearch bar functionality
prepopulated_fieldsAuto-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 ModelAdmin classes for better usability