Django Admin: Create a Superuser and Register Models

Recommended preparation: set up a Django project and read the Django tutorial overview before trying the code.

The Django admin gives authorized staff a built-in interface to manage registered models. After migrating your database, create a superuser, register the Student model and visit /admin/ on your local Django server.

Terminal — create admin tables, account and development server

python manage.py migrate
python manage.py createsuperuser
python manage.py runserver

Open http://127.0.0.1:8000/admin/, sign in using the account you created, and access registered models. The screenshots below show typical admin screens; their appearance may differ by Django version.

On this page — Show page sectionsHide page sections

Admin prerequisites

  • The django.contrib.admin, auth, sessions and messages apps are installed (included in a new Django project).
  • You have run python manage.py migrate.
  • The project URL configuration includes path("admin/", admin.site.urls).
  • You have a model to register, such as Student.

plus2net_demo/urls.py

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path("admin/", admin.site.urls),
    path("students/", include("students.urls")),
]

Create the Student model

students/models.py

from django.db import models

class Student(models.Model):
    name = models.CharField(max_length=100)
    cl = models.CharField(max_length=20, db_column="class")
    mark = models.PositiveSmallIntegerField()
    gender = models.CharField(max_length=20)

    def __str__(self):
        return self.name

Register the model in the admin

students/admin.py — simplest registration

from django.contrib import admin
from .models import Student

admin.site.register(Student)

After registration, the admin site provides add, change and delete interfaces according to user permissions.

Customize list display and filters

students/admin.py — replace the simpler register() example, do not use both

from django.contrib import admin
from .models import Student

@admin.register(Student)
class StudentAdmin(admin.ModelAdmin):
    list_display = ("id", "name", "cl", "mark", "gender")
    list_filter = ("cl", "gender")
    search_fields = ("name",)
    ordering = ("id",)

list_display determines columns; list_filter adds filters; search_fields adds search. Choose one registration approach to avoid AlreadyRegistered.

Create a non-superuser staff account

For routine administration, prefer staff accounts with precisely scoped permissions rather than sharing a superuser credential. You can create users in the admin or with Django authentication tools. is_staff controls admin access, while specific model permissions determine allowed actions.

Screenshots and what they show

Django admin login and navigation screen
Django admin login and navigation screen
Student model visible in the Django admin interface
Student model visible in the Django admin interface

Security and deployment

Never use a known demo password on a public server. Keep DEBUG=False in production, configure trusted hosts and HTTPS, and restrict who can access admin functions. The admin site is not a substitute for application-specific permission checks.

Troubleshooting

  • admin page returns 404: add the admin route to the project URL configuration.
  • relation/table does not exist: run model migrations before visiting the changelist.
  • Student model not shown: register it in admin.py and confirm the app is installed.
  • Permission denied: confirm the user is active/staff and has the required model permissions.
  • AlreadyRegistered: remove duplicate model registration statements.

Continue with MySQL setup for the Student model or forms to create a separate user-facing input experience.

More admin customizations

An alternative: pagination and search on the changelist

@admin.register(Student)
class StudentAdmin(admin.ModelAdmin):
    list_display = ("name", "cl", "mark")
    list_per_page = 25
    search_fields = ("name",)

An alternative: control the model edit-form layout

@admin.register(Student)
class StudentAdmin(admin.ModelAdmin):
    fields = ("name", "cl", "mark", "gender")
    readonly_fields = ()

Change the password for a named Django user

python manage.py changepassword admin_username

Use the admin configuration variants as alternatives. Never place multiple @admin.register(Student) classes in the same app unless you first unregister a previous registration.

Frequently asked questions

Do all Django projects include the admin?

The default Django project enables the admin app. It can be removed or customized for other architectures.

What is the difference between staff and superuser?

A superuser receives every model permission. Staff status allows access to the admin login, but individual permissions still control what normal staff users may do.

Can I register two ModelAdmin classes for the same model?

No. Register a model once. To change its admin behavior, use a single ModelAdmin class or replace the earlier registration.

Previous: List and detail pages

Browse the complete Django tutorial series.

Additional references

Back to top ↑




Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer