Admin

Admin: Today we’re going to:

  • Activate it completely
  • Make it beautiful and useful for your polls app
  • Customize list views, filters, search, inline editing, actions, etc.
  • Add superuser + understand permissions basics
  • Show real-world tips that separate “looks okay” from “production-ready admin”

Let’s build it step by step like I’m sitting next to you.

Step 1: Is Admin Already Enabled? (Quick Check)

Open mysite/settings.py

Look for INSTALLED_APPS — you should see these already there (they come by default):

Python

Also check mysite/urls.py:

Python

If both are there → admin is already technically enabled.

Step 2: Create a Superuser (Admin Login)

Run this once (only needed first time):

Bash

Example session:

text

Now start server:

Bash

Go to: http://127.0.0.1:8000/admin/

Login with the credentials you just created.

→ You should see the default admin dashboard (but no Polls yet!)

Step 3: Register Your Models (Make Polls Visible)

The admin is empty because you haven’t told it about your models yet.

Open polls/admin.py (it’s almost empty by default)

Replace everything with this (modern, clean style):

Python

Save → refresh http://127.0.0.1:8000/admin/

Now you should see:

  • “Questions” and “Choices” under Polls section
  • Nice list views with filters, search, inline choices when editing question
  • Slug auto-filled when creating new question

Step 4: Real-World Polish Touches (What Pros Do)

Add these one by one to QuestionAdmin:

Python

Now you can select multiple questions → Actions dropdown → Mark active/inactive.

Step 5: Quick Test Drive

  1. Go to /admin/
  2. Login
  3. Click “Questions” → see list
  4. Click “Add Question” → see nice form + 3 empty choice rows
  5. Fill question + category + 2–3 choices → Save
  6. Back to list → see your new question + recent icon
  7. Select it + one old → Actions → make inactive → confirm

Bonus: Make Admin Feel Modern (2026 Touch)

Many teams add these tiny improvements:

  1. Change admin title

    In mysite/admin.py (create if missing):

    Python
  2. Add favicon (later with static files)

  3. Use django-jazzmin or django-admin-interface package (very popular in India 2026)

    Bash

    Then add ‘jazzmin’ before ‘django.contrib.admin’ in INSTALLED_APPS

    → Beautiful sidebar, dark mode, charts, etc.

Common Beginner Pain Points

Problem Likely Cause Fix
No “Polls” section Forgot admin.site.register(Question) Add @admin.register or admin.site.register
No choices inline Forgot inlines = [ChoiceInline] Add the inline class
Slug not auto-filling No prepopulated_fields Add prepopulated_fields = {‘slug’: (‘question_text’,)}
Can’t see old questions ordering in Meta or list ordering Add ordering = [‘-pub_date’] in model Meta
“You don’t have permission” Not superuser or wrong user Login with superuser or give staff permissions

Your Quick Homework

  1. Add the full admin.py code shown above
  2. Create 4–5 questions + choices via admin
  3. Play with filters, search, bulk actions
  4. Try marking some inactive → see them disappear from frontend list (if you filtered is_active=True)
  5. (Optional) Install django-jazzmin → see how pretty it becomes

Tell me what feels next:

  • “Admin looks great! Now show me permissions & staff users”
  • “How to add charts or custom admin pages?”
  • “I want to customize change list even more (custom columns, CSS)”
  • “Got error when saving – here’s message”
  • Or finally ready for: “Let’s finish the voting system – form + POST + F() + results”

You now have a production-grade admin backend in ~30 lines of code — this is why people fall in love with Django. You’re doing fantastic — let’s keep building! 🚀🇮🇳

You may also like...

Leave a Reply

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