sideabr fixes 7 atemepts in it
This commit is contained in:
@@ -28,6 +28,23 @@ class Igny8AdminConfig(AdminConfig):
|
|||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
super().ready()
|
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
|
# Import Unfold AFTER apps are ready
|
||||||
from unfold.admin import ModelAdmin as UnfoldModelAdmin
|
from unfold.admin import ModelAdmin as UnfoldModelAdmin
|
||||||
|
|
||||||
|
|||||||
@@ -25,18 +25,32 @@ class Igny8AdminSite(UnfoldAdminSite):
|
|||||||
urls = super().get_urls()
|
urls = super().get_urls()
|
||||||
return 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
|
Customize the app list to organize models into logical groups
|
||||||
NO EMOJIS - Unfold handles all icons via Material Design
|
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
|
# 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)
|
# Define our custom groups with their models (using object_name)
|
||||||
# Organized by business function - Material icons configured in Unfold
|
# Organized by business function - Material icons configured in Unfold
|
||||||
custom_groups = {
|
custom_groups = {
|
||||||
'Igny8_Core_Auth': {
|
'Accounts & Users': {
|
||||||
'models': [
|
'models': [
|
||||||
('igny8_core_auth', 'Account'),
|
('igny8_core_auth', 'Account'),
|
||||||
('igny8_core_auth', 'User'),
|
('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 = []
|
organized_apps = []
|
||||||
|
|
||||||
for group_name, group_config in custom_groups.items():
|
for group_name, group_config in custom_groups.items():
|
||||||
@@ -171,12 +186,18 @@ class Igny8AdminSite(UnfoldAdminSite):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if group_models:
|
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({
|
organized_apps.append({
|
||||||
'name': group_name,
|
'name': group_name,
|
||||||
'app_label': group_name.lower().replace(' ', '_').replace('&', 'and'),
|
'app_label': first_model_app_label, # Use real app_label, not fake one
|
||||||
'app_url': '#',
|
'app_url': f'/admin/{first_model_app_label}/', # Real URL, not '#'
|
||||||
'has_module_perms': True,
|
'has_module_perms': True,
|
||||||
'models': group_models,
|
'models': group_models,
|
||||||
})
|
})
|
||||||
|
|
||||||
return organized_apps
|
return organized_apps
|
||||||
|
|
||||||
|
|
||||||
|
# Instantiate custom admin site
|
||||||
|
admin_site = Igny8AdminSite(name='admin')
|
||||||
|
|||||||
@@ -652,7 +652,7 @@ UNFOLD = {
|
|||||||
},
|
},
|
||||||
"SIDEBAR": {
|
"SIDEBAR": {
|
||||||
"show_search": True,
|
"show_search": True,
|
||||||
"show_all_applications": True,
|
"show_all_applications": False, # Use custom app_list from Igny8AdminSite
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user