How to have 2 different admin sites in a Django project?

You can subclass Django’s AdminSite (put it eg. in admin.py in your project root):

from django.contrib.admin.sites import AdminSite

class MyAdminSite(AdminSite):
    pass
    #or overwrite some methods for different functionality

myadmin = MyAdminSite(name="myadmin")   

At least from 1.9 on you need to add the name parameter to make it work properly. This is used to create the revers urls so the name has to be the one from the urls.py.

Then you can use it in your app’s admin.py the same way as you do with the normal AdminSite instance:

from myproject.admin import myadmin
myadmin.register(MyModel_A)

You also need to define some urls for it (in your project’s urls.py):

from django.urls import path
from myproject.admin import admin, myadmin

urlpatterns = [
    path('admin/', admin.site.urls),
    path('myadmin/', myadmin.urls),
]

Also see this: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adminsite-objects

Leave a Comment