sideabr fixes 7 atemepts in it

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-14 21:23:07 +00:00
parent 93ecb5ceb8
commit 9150b60c2d
3 changed files with 45 additions and 7 deletions

View File

@@ -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

View File

@@ -25,18 +25,32 @@ class Igny8AdminSite(UnfoldAdminSite):
urls = super().get_urls()
return urls
def get_app_list(self, request):
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, 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')

View File

@@ -652,7 +652,7 @@ UNFOLD = {
},
"SIDEBAR": {
"show_search": True,
"show_all_applications": True,
"show_all_applications": False, # Use custom app_list from Igny8AdminSite
},
}