mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 20:40:17 +02:00
Merge branch 'admin_performance_tuning' into 'master'
Admin performance tuning for group and state See merge request allianceauth/allianceauth!1318
This commit is contained in:
commit
5c3ded6b07
@ -399,7 +399,7 @@ class UserAdmin(BaseUserAdmin):
|
|||||||
def formfield_for_manytomany(self, db_field, request, **kwargs):
|
def formfield_for_manytomany(self, db_field, request, **kwargs):
|
||||||
"""overriding this formfield to have sorted lists in the form"""
|
"""overriding this formfield to have sorted lists in the form"""
|
||||||
if db_field.name == "groups":
|
if db_field.name == "groups":
|
||||||
kwargs["queryset"] = Group.objects.all().order_by(Lower('name'))
|
kwargs["queryset"] = Group.objects.all().order_by(Lower('name'))
|
||||||
return super().formfield_for_manytomany(db_field, request, **kwargs)
|
return super().formfield_for_manytomany(db_field, request, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
@ -438,7 +438,7 @@ class StateAdmin(admin.ModelAdmin):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def formfield_for_manytomany(self, db_field, request, **kwargs):
|
def formfield_for_manytomany(self, db_field, request, **kwargs):
|
||||||
"""overriding this formfield to have sorted lists in the form"""
|
"""overriding this formfield to have sorted lists in the form"""
|
||||||
if db_field.name == "member_characters":
|
if db_field.name == "member_characters":
|
||||||
kwargs["queryset"] = EveCharacter.objects.all()\
|
kwargs["queryset"] = EveCharacter.objects.all()\
|
||||||
.order_by(Lower('character_name'))
|
.order_by(Lower('character_name'))
|
||||||
@ -448,8 +448,10 @@ class StateAdmin(admin.ModelAdmin):
|
|||||||
elif db_field.name == "member_alliances":
|
elif db_field.name == "member_alliances":
|
||||||
kwargs["queryset"] = EveAllianceInfo.objects.all()\
|
kwargs["queryset"] = EveAllianceInfo.objects.all()\
|
||||||
.order_by(Lower('alliance_name'))
|
.order_by(Lower('alliance_name'))
|
||||||
|
elif db_field.name == "permissions":
|
||||||
|
kwargs["queryset"] = Permission.objects.select_related("content_type").all()
|
||||||
return super().formfield_for_manytomany(db_field, request, **kwargs)
|
return super().formfield_for_manytomany(db_field, request, **kwargs)
|
||||||
|
|
||||||
def has_delete_permission(self, request, obj=None):
|
def has_delete_permission(self, request, obj=None):
|
||||||
if obj == get_guest_state():
|
if obj == get_guest_state():
|
||||||
return False
|
return False
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
from django.contrib.auth.models import Permission
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth.models import Group as BaseGroup, User
|
from django.contrib.auth.models import Group as BaseGroup, User
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
@ -96,8 +97,7 @@ class HasLeaderFilter(admin.SimpleListFilter):
|
|||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
class GroupAdmin(admin.ModelAdmin):
|
class GroupAdmin(admin.ModelAdmin):
|
||||||
list_select_related = ('authgroup',)
|
|
||||||
ordering = ('name',)
|
ordering = ('name',)
|
||||||
list_display = (
|
list_display = (
|
||||||
'name',
|
'name',
|
||||||
@ -122,7 +122,7 @@ class GroupAdmin(admin.ModelAdmin):
|
|||||||
qs = super().get_queryset(request)
|
qs = super().get_queryset(request)
|
||||||
if _has_auto_groups:
|
if _has_auto_groups:
|
||||||
qs = qs.prefetch_related('managedalliancegroup_set', 'managedcorpgroup_set')
|
qs = qs.prefetch_related('managedalliancegroup_set', 'managedcorpgroup_set')
|
||||||
qs = qs.prefetch_related('authgroup__group_leaders')
|
qs = qs.prefetch_related('authgroup__group_leaders').select_related('authgroup')
|
||||||
qs = qs.annotate(
|
qs = qs.annotate(
|
||||||
member_count=Count('user', distinct=True),
|
member_count=Count('user', distinct=True),
|
||||||
)
|
)
|
||||||
@ -168,6 +168,11 @@ class GroupAdmin(admin.ModelAdmin):
|
|||||||
filter_horizontal = ('permissions',)
|
filter_horizontal = ('permissions',)
|
||||||
inlines = (AuthGroupInlineAdmin,)
|
inlines = (AuthGroupInlineAdmin,)
|
||||||
|
|
||||||
|
def formfield_for_manytomany(self, db_field, request, **kwargs):
|
||||||
|
if db_field.name == "permissions":
|
||||||
|
kwargs["queryset"] = Permission.objects.select_related("content_type").all()
|
||||||
|
return super().formfield_for_manytomany(db_field, request, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Group(BaseGroup):
|
class Group(BaseGroup):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user