Django Admin

Django Admin is a backend user interface for web-application super user and staff users. You can register you models in admin site and can control create, view, change and delete activities in models. A superuser can be created first with createsuperuser command and then the other users can be created from Admin interface.

Django Admin - Users & Groups

To create your first user as superuser run:

python createsuperuser

It will then ask to input below fields and confirm Superuser created successfully.

    Username : 
    Email address:
    Password (again):

You may visit the admin page with below url (if development server is running):

django admin login

You can then use the aforementioned login credentials in the Django Administration page. Other Users and authentication Groups can be created with Admin interface.

django admin login

Register Model with Django Admin

To register models with admin interface simply add below statement in module. Here Blog is an example of Model name.
    from django.contrib import admin
    from .models import Blog

Django Admin Options

Django admin can offer a dashboard with many options to view and manage model data. Below are some admin options and their implications.

  • list_display: It can display list of each record in given order.
  •     list_display = ['field1', 'field2', ...]
  • list_filter: It can add filters to model with mentioned fields
  •     list_filter = ['field1', 'field2', ...]
  • fields: It is used to organise detail view layout.
  •     fields = ['field1', 'field2', ('field3', 'field4'), ...]
  • fieldsets: It is used for sectioning the detail view.
  •     fieldsets = (
         (None, {
         'fields': ('field1', 'field2', ...)
         ('Availability', {
         'fields': ('field1', 'field2', ...)
  • list_editable: It makes mention fields available for quick editing.
  •     list_editable = ['field1','field2',...]
  • search_fields: It searches the query in mentioned model fields only.
  •     search_fields = ['field1','field2',...]
  • exclude: It is the negative list of elements to be excluded from admin console display.
  •     exclude = ['field1','field2',...]
  • ordering: It defines the tuple for ordering model data.
  •     ordering = ('field1', ...)
  • list_per_page: It can be used for pagination. Example: 25 rows per page
  •     list_per_page = 25
  • radio_fields: It can convert select fields or dropdown fields to radio fields.
  •     radio_fields = {"field_name": admin.HORIZONTAL, ...}