How to Change Your Admin Site's Look, Feel and Behavior in 3 Steps

Posted by Chris Bartos on April 4, 2016

Sometimes the admin site works great out of the box. Other times, you need to add some custom code to certain parts of your admin site.

Maybe, you want some custom tables that shows your revenue for the month (i.e. you have an e-commerce site), maybe you’d like to create a button so you could upload batch SKUs for product inventory in your e-commerce site.

The sky really is the limit. This post will show you not only how to update and custom the admin templates, but it will also give you a clue to how to update the actual admin views so you can change the behavior of the entire admin interface.

Step 1: Override Admin Templates

Create a an admin directory in your project’s templates directory. Create a subdirectory inside of the admin directory that will be the name of your app (i.e. my_app).

You have some options that you could edit for specific apps:

  • app_index.html
  • change_form.html
  • change_list.html
  • delete_confirmation.html
  • object_history.html

All the other ones, you would just copy into your newly created admin directory.

Step 2: Override Admin View by Subclassing AdminSite

If you’d like to change how your Admin site behaves, you’ll need to subclass django.contrib.admin.AdminSite:

from django.contrib.admin import AdminSite
from .models import MyModel
class MyAdminSite(AdminSite):
    site_header = "My Super Awesome Customized Admin Site"
    # More stuff including view methods that you can also override.

Any method or attribute you find here can be overridden. You can literally change how the entire Admin site behaves and works.

Step 3: Instantiate your Admin Class and Register your Models on it

Once your admin site works the way you want it to, you can instantiate and register your models to it:

admin_site = MyAdminSite(name="myadmin")
admin_site.register(MyModel)

Now, you can add your admin to your urlconf:

from django.conf.urls import url
from my_app.admin import admin_site

urlpatterns = [
    url(r'^myadmin/', admin_site.urls),
]

Now, you can change the look and feel of you admin site, and even update the behavior of the entire admin site. What would you like to add to your site?



What do you do after the Official Django Tutorial?

Here's what you'll learn:

  1. Start writing tests
  2. Increase the size / complexity of the Polls application.
  3. Learn how to code in Django by reading the Django source code.
  4. Finding code snippets to use in your website by reading the code of other websites.
  5. Using Javascript in a web app.
  6. Deploying on Heroku and AWS.
We won't send you spam. Unsubscribe at any time. Powered by ConvertKit


Get some value from this post? Please like and share this post because more people also deserve some value. :-)