1
1
from django .contrib .admin import site
2
2
from django .contrib .contenttypes .models import ContentType
3
3
from django .db import models
4
- from django .db .models import F
4
+ from django .db .models import F , Prefetch
5
5
from django .urls import reverse
6
6
from django .utils .text import capfirst
7
7
from django .utils .translation import get_language , gettext_lazy as _
@@ -17,7 +17,7 @@ def get_by_natural_key(self, slug):
17
17
return self .get (slug = slug )
18
18
19
19
def as_list (self , request , include_remaining = True ):
20
- # Convert to convienent dict
20
+ # Convert to convenient dict
21
21
model_dicts = {}
22
22
23
23
original_app_list = site .get_app_list (request )
@@ -56,8 +56,16 @@ def as_list(self, request, include_remaining=True):
56
56
# Create new list based on our groups, using the model_dicts constructed above. # noqa
57
57
result = []
58
58
app_list = self .annotate (
59
- localized_name = F (f"translations__{ language_code } " )
60
- ).prefetch_related ("models" , "applink_set" )
59
+ localized_name = F (f"translations__{ language_code } " ),
60
+ ).prefetch_related (
61
+ "models" ,
62
+ Prefetch (
63
+ "applink_set" ,
64
+ queryset = AppLink .objects .annotate (
65
+ localized_name = F (f"translations__{ language_code } " ),
66
+ ),
67
+ ),
68
+ )
61
69
active_app = request .path == reverse ("admin:index" )
62
70
for app in app_list :
63
71
models = []
@@ -71,9 +79,7 @@ def as_list(self, request, include_remaining=True):
71
79
if o ["active" ]:
72
80
active = True
73
81
74
- for app_link in app .applink_set .annotate (
75
- localized_name = F (f"translations__{ language_code } " )
76
- ):
82
+ for app_link in app .applink_set .all ():
77
83
models .append (
78
84
{
79
85
"name" : app_link .localized_name or app_link .name ,
0 commit comments