Topics in this subject
Django 3 min read Updated 11 Aug 2026

Django Admin Interface

Registering models and customizing the built-in CMS.

🧑‍🏫 Sabse pehle — simple mein samjho#

Backend developers ko test karne ke liye ya non-technical staff ko data manage karne ke liye ek Dashboard banana padta hai jahan se wo log data Add/Edit/Delete kar sakein. Dusre frameworks mein tumhe iske liye poora admin panel zero se banana padta hai. Django ka magic yahi hai ki ye poora CMS (Content Management System) tumhe bilkul Free aur pehle din se bana kar de deta hai. Tumhe bas apne database models ko usme "Register" karna hota hai.

1. Creating a Superuser#

Before you can log into the admin panel, you need an account with administrative privileges. Run this command in your terminal and follow the prompts (email, username, password):

python manage.py createsuperuser

Now, start your server and navigate to http://localhost:8000/admin/. Log in with your new credentials.

2. Registering Models#

By default, the admin panel only shows Users and Groups. To see your custom models (like Post or Product), you must register them in the admin.py file of their respective app.

blog/admin.py

from django.contrib import admin
from .models import Post

# The simplest way to register a model
admin.site.register(Post)

3. Customizing the Admin Interface#

While simple registration works, it only displays the string representation (the __str__ method) of the object in a single column. If you want a rich table with filters, search bars, and multiple columns, you create a custom ModelAdmin class.

blog/admin.py

from django.contrib import admin
from .models import Post

# Define the custom admin class
class PostAdmin(admin.ModelAdmin):
    # Columns to display in the list view
    list_display = ('title', 'author', 'created_at')
    
    # Add a sidebar to filter results by specific fields
    list_filter = ('created_at', 'author')
    
    # Add a search bar at the top to search specific fields
    search_fields = ('title', 'content')
    
    # Pre-populate fields automatically (e.g., generating a slug from the title)
    prepopulated_fields = {'slug': ('title',)}
    
    # Fields that should be read-only in the edit menu
    readonly_fields = ('created_at',)

# Register the model along with its custom admin configuration
admin.site.register(Post, PostAdmin)

4. Advanced: Inline Models#

If you have related models (like a Post having many Comments), you can edit the comments directly from within the Post's edit page instead of going to a separate Comments section.

from django.contrib import admin
from .models import Post, Comment

# Use TabularInline (table format) or StackedInline (vertical format)
class CommentInline(admin.TabularInline):
    model = Comment
    extra = 1 # Shows 1 empty extra row to add a new comment quickly

class PostAdmin(admin.ModelAdmin):
    # Add the inline to the main model's admin
    inlines = [CommentInline]

admin.site.register(Post, PostAdmin)

The Django Admin is incredibly powerful and heavily customizable. It is a massive time-saver for prototyping and internal company tooling.