How to Customize Django Admin Site?

Published On: 09/11/2022 | Category: Django

Hi Dev,

This is a short guide on how to customize django admin site. I explained simply about how to customize django admin. it's simple example of django admin interface customize example. I would like to share with you django admin site customize example tutorial.

The Django framework has a potent management tool called admin. It can instantly add, remove, or change any database model from a web interface right out of the box. However, you may modify the Django admin to enhance your admin capabilities by adding a little extra code.

Here i explained simply step by step example of how to customize django admin site.

Step 1: Create a Project

In this step, we’ll create a new django project using the django-admin. Head back to your command-line interface and run the following command:

django-admin startproject example

Step 2: Create a App

Now we'll create a single app called core to store a list of post names. We're keeping things intentionally basic. Stop the local server with Control+c and use the startapp command to create this new app.

python startapp core

Step 3: Update

In this step we require to do two things in our file, One is our installed app name Add the below lines to your file:

Next, you need to add it in the file as follows:


Step 4: Create a Model

In this step we will require the database model for storing contacts.Open the core/ file and add the following code:

from django.db import models
from django.db.models.deletion import CASCADE

class Category(models.Model):
    cat_romance  =  "Romance"
    cat_fantacy  =  "Fantacy"
    cat_thriller=  "Thriller"
    cat_horror  =  "Horror"
    cat_crime  =  "Crime"
    cat_true_story=  "True Story"
    category  =  models.CharField(
        (cat_crime, cat_crime),
        (cat_fantacy, cat_fantacy),
        (cat_horror, cat_horror),
        (cat_romance, cat_romance),
        (cat_thriller, cat_thriller),
        (cat_true_story, cat_true_story)

    def  __str__(self):
        return  self.category

class  Publisher(models.Model):
    publisher_name  =  models.CharField(max_length=100)
    publish_date  =  models.DateField

    def  __str__(self):
        return  self.publisher_name

class  Author(models.Model):
    gender_male  =  "Male"
    gender_female  =  "Female"
    gender_other  =  "Other"
    name  =  models.CharField(max_length=100)
    gender  =  models.CharField(max_length=100,
        (gender_female, gender_female),
        (gender_male, gender_male),
        (gender_other, gender_other)
    country  =  models.CharField(max_length=100)

    def  __str__(self):

class  Details(models.Model):
    book_name  =  models.CharField(max_length=100)
    category = models.ForeignKey(Category, on_delete=CASCADE)
    pages = models.IntegerField(default=1)
    publisher  =  models.ForeignKey(Publisher, on_delete=models.CASCADE)
    Author  =  models.ForeignKey(Author, on_delete=CASCADE)

    def  __str__(self):
        return  self.book_name

Ok, all set. We can engender a migrations file for this change, then integrate it to our database via migrate.

python makemigrations
python migrate

Step 5: Update

from django.db import models
from .models import Category, Publisher ,Details, Author

class  categoryAdmin(admin.ModelAdmin):

class  publisherAdmin(admin.ModelAdmin):

class  detailsAdmin(admin.ModelAdmin):

class  authorAdmin(admin.ModelAdmin):
    pass, categoryAdmin), publisherAdmin), detailsAdmin), authorAdmin)  

Step 6: Run the Server

In this step, we’ll run the local development server for playing with our app without deploying it to the web.

python runserver

You can now log in using the superuser credentials at

Now, customize the Django Admin Site...

  1. Setting plural text for models
  2. Changing the Django administration header text
  3. Removing the default groups
  4. Using list_display
  5. Adding an image to Django admin

Setting plural text for models

By adding the following code to, we can change how the models category and information appear on the admin site.

class  Category(models.Model):
  # ...
    class  Meta:  #new
        verbose_name_plural  =  "Categories"     

class  Details(models.Model):
  # ...
    class  Meta:   #new
        verbose_name_plural  =  "Details"

Changing the Django administration header text

Instead, add the following code to to update the admin site header text, login page, and HTML title tag for our bookshop.  =  "Custom bookstore admin"  =  "Custom bookstore admin site"  =  "Custom Bookstore Admin"

The Django administration text that shows on the login page and the admin site is modified by the site header. Every admin page's title text is modified by the site title.

Removing the default groups

Consider the scenario where we want to remove the Groups app that comes with our Django admin site by default.

We will go ahead and import it then unregister it in

from  django.contrib.auth.models  import  Group  # new
#...  # new

If you like, you could also go ahead and unregister users through the same process.

Using list_display

Additionally, you might want more than one column to be visible on the change list page for your details model. We must modify in order to add additional fields.

class  detailsAdmin(admin.ModelAdmin):

Adding an image to Django admin

Using list display, we might also wish to include the author's picture in addition to their name. We must first install a third-party programme named pillow in order to accomplish that.

pip install pillow

Then, open and add the following code. This code tells Django where to store the images.

import os # at the top
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR , 'media')

Now let’s create the media folder and add an images folder inside it.

mkdir media\images

Then, open and add the code below to add our media folder to the static files.

# below the other imports
from . import settings
from django.contrib.staticfiles.urls import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns


urlpatterns +=staticfiles_urlpatterns()
urlpatterns +=static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

We will import mark safe into and also add the picture field to our Author model. Then, we'll include a feature that lets us view the image on our admin site.

In this step, we need to create the views for performing the fetch record to the database.Open the core/ file and add:

# at the top
from django.utils.safestring import mark_safe

# in our Author model
class  Author(models.Model):
    # .....
    author_pic = models.ImageField(upload_to='images/', null=True)

    def  image_tag(self):
        return mark_safe('<img src="/../../media/%s" width="150" height="150" />' % (self.author_pic))

    image_tag.allow_tags = True     

Now let us make migrations then migrate to reflect the changes in our database.

python makemigrations
python migrate

Finally, we’ll call our function inside the list display. Let’s go to our and modify the authorAdmin().

class  authorAdmin(admin.ModelAdmin):

I Hope It will help you....