Chapter 1: Django Admin

The Django Admin

Many beginners see the admin as “just a toy for learning” — but in real Indian startups, internal tools, content platforms, SaaS products, inventory systems, and even early versions of fairly large apps, the Django admin is often the main backend interface used by non-technical team members (content writers, ops, support, founders) for months or even years.

Today I’m going to teach you how to go from “empty admin login screen” to beautiful, powerful, production-ready admin for your polls app — step by step, very slowly, like I’m sitting next to you looking at your screen.

Let’s do this properly.

Step 0 – Quick Reality Check (What You Should Already Have)

Before we start, confirm these 3 things:

  1. django.contrib.admin is in INSTALLED_APPS (it is by default)
  2. path(‘admin/’, admin.site.urls) is in mysite/urls.py (also default)
  3. You already ran python manage.py createsuperuser at least once

If any is missing → fix it now.

Go to http://127.0.0.1:8000/admin/ Login → you should see the default dashboard (but no Polls yet).

Step 1 – The Minimal “Make It Appear” Version

Open polls/admin.py

Replace everything with this (old-school simple way):

Python

Save → refresh admin page.

→ Boom! You now see “Questions” and “Choices” under a new “Polls” section.

You can already:

  • Add new questions
  • Add choices (but you have to choose question manually each time)
  • Edit / delete existing ones

This is already useful — but ugly and not efficient.

Step 2 – Modern & Beautiful Way (Recommended 2026 Style)

Replace polls/admin.py with this much better version:

Python

What You Just Got (After Refreshing Admin)

  • Truncated question text (no super-long titles breaking layout)
  • Colored category (visual cue)
  • Green/Red recent icon
  • Active/Inactive icons
  • Total votes column (aggregated from choices)
  • Choices editable inline (add/edit/delete choices without leaving question page)
  • Pre-filled slug
  • Collapsible fieldsets
  • Search, filters, date hierarchy, pagination
  • Bulk actions (select multiple → activate/deactivate)

Step 3 – Add Bulk Actions (Very Useful in Real Life)

Add this inside QuestionAdmin class:

Python

Now you can select many questions → Actions dropdown → deactivate old polls in bulk.

Step 4 – Customize Admin Titles & Look

Create or edit mysite/admin.py:

Python

→ Much friendlier header.

Step 5 – Quick Test Drive (Do This Now)

  1. Go to /admin/
  2. Login
  3. Click “Questions” → see nice columns, filters, search
  4. Click “Add Question” → see inline choices + auto-slug
  5. Create 3–4 questions + choices
  6. Select 2 → Actions → make inactive → see them disappear from frontend list (if filtered)
  7. Search for a keyword → see instant results

Real-World Pro Tips (2026 Edition)

  • Install django-jazzmin or django-admin-interface (very popular in India right now)
    Bash

    Add ‘jazzmin’before‘django.contrib.admin’ in INSTALLED_APPS → beautiful sidebar, dark mode, quick stats.

  • Use list_editable = (‘is_active’, ‘category’) → edit fields directly in list view
  • Add list_select_related = (‘category’,) → faster queries if you have foreign keys
  • For large data: raw_id_fields, autocomplete_fields, django-admin-autocomplete-filter

Common “Why Isn’t It Working?” Moments

Problem Cause Fix
No Polls section Forgot @admin.register or admin.site.register Add registration
Choices not inline No inlines Add inlines = [ChoiceInline]
Slug not auto-fill No prepopulated_fields Add the line
No vote count column No aggregation method Add vote_count method
“You don’t have permission” Logged in with normal user Use superuser or give is_staff=True + permissions

Your Quick Task Right Now

  1. Replace your polls/admin.py with the full code above
  2. Create 5 questions + choices via admin
  3. Play with filters, search, bulk actions
  4. Change one question to inactive → check if frontend list respects is_active=True filter

Tell me what you want next:

  • “Admin looks awesome! Now show me staff users & permissions”
  • “How to add charts (vote stats) to admin dashboard?”
  • “I want autocomplete for questions in Choice admin”
  • “Got error when saving – here’s the message”
  • Or finally: “Let’s implement the full voting system – form, POST, F(), results”

You now have a production-grade, beautiful admin backend in ~60 lines of code. This is one of the reasons people say “Django batteries are included”.

You’re doing incredible — let’s keep this energy! 🚀🇮🇳

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *