How to Configure django-admin-tools for Multiple Admin Sites Without Affecting the Default Admin
I'm using django-admin-tools
in my Django
project to create a dashboard-like custom admin site. I've successfully set up django-admin-tools
following the official documentation.
My goal is to create a custom admin site and configure django-admin-tools
to work exclusively for this site, without affecting the default Django admin site
. Below is a simplified version of my code:
# Custom Admin Site
class AdminSiteDashboard(AdminSite):
site_header = 'Dashboard'
site_title = 'Dashboard Portal'
index_title = 'Welcome to My Dashboard'
admin_site_dashboard = AdminSiteDashboard(name='admin_dashboard')
# url patterns
urlpatterns = [
path('admin_tools/', include('admin_tools.urls')),
path('admin/', admin.site.urls),
path('dashboard/', admin_site_dashboard.urls),
...
]
# settings
ADMIN_TOOLS_MENU = {
'base.admin_site.admin_site_dashboard': 'base.admin_tools.base_admin_menu.CustomMenu',
}
ADMIN_TOOLS_INDEX_DASHBOARD = {
'base.admin_site.admin_site_dashboard': 'base.admin_tools.base_admin_dashboard.CustomIndexDashboard',
}
ADMIN_TOOLS_APP_INDEX_DASHBOARD = {
'base.admin_site.admin_site_dashboard': 'base.admin_tools.base_admin_dashboard.CustomAppIndexDashboard',
}
I expected that by configuring django-admin-tools
only for admin_site_dashboard
, the default admin site would remain unaffected. However, after setting it up as shown above, I can access the dashboard at dashboard/
, but I encounter an error when trying to access the default admin site at admin/
. The error is:
ValueError at /admin/ Dashboard menu matching "{'base.admin_site.admin_site_dashboard': 'base.admin_tools.base_admin_menu.CustomMenu'}" not found,{% if user.is_active and user.is_staff and not is_popup %}{% admin_tools_render_menu_css %}{% endif %}
Is there a way to configure django-admin-tools
so that it only applies to the custom admin site and does not interfere with the default Django admin site?
Any advice or suggestions would be greatly appreciated.
from django-admin-tools docs https://django-admin-tools.readthedocs.io/en/latest/multiple_admin_sites.html
You should add 'django.contrib.admin.site' to admin tools settings
ADMIN_TOOLS_MENU = {
'django.contrib.admin.site': 'base.admin_site.admin',
'base.admin_site.admin_site_dashboard': 'base.admin_tools.base_admin_menu.CustomMenu',
}
ADMIN_TOOLS_INDEX_DASHBOARD = {
'django.contrib.admin.site': 'base.admin_site.admin',
'base.admin_site.admin_site_dashboard': 'base.admin_tools.base_admin_dashboard.CustomIndexDashboard',
}