unfoldadmin / django-unfold

Modern Django admin theme for seamless interface development

Home Page:https://unfoldadmin.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multi-Admin Site Issue

Ehco1996 opened this issue · comments

commented

When attempting to set up a multi-admin site, I encounter an error. After investigation, I believe this issue is caused by the hardcoded URL {% url "admin:toggle_sidebar" %} in template.

Error Message

Reverse for 'toggle_sidebar' not found. 'toggle_sidebar' is not a valid view function or pattern name.
<div class="relative z-50">
<div @click="sidebarDesktopOpen = !sidebarDesktopOpen"
hx-get="{% url "admin:toggle_sidebar" %}"
hx-swap="none"
class="block bg-white border cursor-pointer fixed flex h-6 hidden items-center justify-center rounded-full text-gray-500 top-5 -translate-x-1/2 w-6 z-50 xl:flex dark:bg-gray-800 dark:border-gray-700 dark:text-gray-200"
:class="{'ml-6 rotate-180': !sidebarDesktopOpen, 'ml-72': sidebarDesktopOpen}">
<span class="material-symbols-outlined md-16">
first_page
</span>

Expected Behavior

I expect to be able to create multiple admin sites with their own URLs and configurations. However, the hardcoded URL seems to be preventing this from happening.

Reproducible Steps

  • admin.py
from django.contrib.admin import AdminSite
from apps.relay.models import XXModel
from unfold.admin import ModelAdmin


class UserAdminSite(AdminSite):
    site_header = "xxx"
    site_title = "xxx"
    index_title = "xxx"

user_admin_site = UserAdminSite(name="user_admin")

class XXAdmin(ModelAdmin):
    list_display = ("id", "user", "created_at", "updated_at")

user_admin_site.register(XXModel, XXAdmin)

urls.py

urlpatterns = [
    path("admin/", admin.site.urls),
    path("user_admin/", user_admin_site.urls),
]
commented

o i found that i should use from unfold.sites import UnfoldAdminSite rather than from django.contrib.admin import AdminSite from https://unfoldadmin.com/blog/migrating-django-admin-unfold

thanks for your great work 💗