From 9150b60c2d1ce2ea35942d508088544ddffe52ec Mon Sep 17 00:00:00 2001 From: "IGNY8 VPS (Salman)" Date: Sun, 14 Dec 2025 21:23:07 +0000 Subject: [PATCH] sideabr fixes 7 atemepts in it --- backend/igny8_core/admin/apps.py | 17 ++++++++++++++++ backend/igny8_core/admin/site.py | 33 ++++++++++++++++++++++++++------ backend/igny8_core/settings.py | 2 +- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/backend/igny8_core/admin/apps.py b/backend/igny8_core/admin/apps.py index 1c2a9258..837e3086 100644 --- a/backend/igny8_core/admin/apps.py +++ b/backend/igny8_core/admin/apps.py @@ -28,6 +28,23 @@ class Igny8AdminConfig(AdminConfig): def ready(self): super().ready() + + # Replace default admin.site with our custom Igny8AdminSite + # IMPORTANT: Must copy all registrations from old site to new site + # because models register themselves before ready() is called + from igny8_core.admin.site import admin_site + import django.contrib.admin as admin_module + + # Copy all model registrations from the default site to our custom site + old_site = admin_module.site + admin_site._registry = old_site._registry.copy() + admin_site._actions = old_site._actions.copy() + admin_site._global_actions = old_site._global_actions.copy() + + # Now replace the default site + admin_module.site = admin_site + admin_module.sites.site = admin_site + # Import Unfold AFTER apps are ready from unfold.admin import ModelAdmin as UnfoldModelAdmin diff --git a/backend/igny8_core/admin/site.py b/backend/igny8_core/admin/site.py index 905ab564..c982d8de 100644 --- a/backend/igny8_core/admin/site.py +++ b/backend/igny8_core/admin/site.py @@ -24,19 +24,33 @@ class Igny8AdminSite(UnfoldAdminSite): """Get admin URLs without custom dashboard""" urls = super().get_urls() return urls + + def each_context(self, request): + """ + Override context to ensure our custom app_list is always used + This is called by all admin templates for sidebar rendering + """ + context = super().each_context(request) + # Force our custom app list to be used everywhere + context['available_apps'] = self.get_app_list(request) + return context - def get_app_list(self, request): + def get_app_list(self, request, app_label=None): """ Customize the app list to organize models into logical groups NO EMOJIS - Unfold handles all icons via Material Design + + Args: + request: The HTTP request + app_label: Optional app label to filter (used for app index pages) """ # Get the default app list - app_dict = self._build_app_dict(request) + app_dict = self._build_app_dict(request, app_label) # Define our custom groups with their models (using object_name) # Organized by business function - Material icons configured in Unfold custom_groups = { - 'Igny8_Core_Auth': { + 'Accounts & Users': { 'models': [ ('igny8_core_auth', 'Account'), ('igny8_core_auth', 'User'), @@ -155,7 +169,8 @@ class Igny8AdminSite(UnfoldAdminSite): }, } - # Build the organized app list + # ALWAYS build and return our custom organized app list + # regardless of app_label parameter (for consistent sidebar on all pages) organized_apps = [] for group_name, group_config in custom_groups.items(): @@ -171,12 +186,18 @@ class Igny8AdminSite(UnfoldAdminSite): break if group_models: + # Get the first model's app_label to use as the real app_label + first_model_app_label = group_config['models'][0][0] organized_apps.append({ 'name': group_name, - 'app_label': group_name.lower().replace(' ', '_').replace('&', 'and'), - 'app_url': '#', + 'app_label': first_model_app_label, # Use real app_label, not fake one + 'app_url': f'/admin/{first_model_app_label}/', # Real URL, not '#' 'has_module_perms': True, 'models': group_models, }) return organized_apps + + +# Instantiate custom admin site +admin_site = Igny8AdminSite(name='admin') diff --git a/backend/igny8_core/settings.py b/backend/igny8_core/settings.py index 4018ac15..986a9701 100644 --- a/backend/igny8_core/settings.py +++ b/backend/igny8_core/settings.py @@ -652,7 +652,7 @@ UNFOLD = { }, "SIDEBAR": { "show_search": True, - "show_all_applications": True, + "show_all_applications": False, # Use custom app_list from Igny8AdminSite }, }