Performance improvement on parentadmin

fix_request_path_info^2
Safa Arıman 2020-06-10 10:56:36 +03:00
parent eed4e9fa4a
commit 8b35063f58
1 changed files with 3 additions and 2 deletions

View File

@ -146,13 +146,14 @@ class PolymorphicParentModelAdmin(admin.ModelAdmin):
"""
self._lazy_setup()
choices = []
for model in self.get_child_models():
content_types = ContentType.objects.get_for_models(*self.get_child_models(), for_concrete_models=False)
for model, ct in content_types.items():
perm_function_name = "has_{0}_permission".format(action)
model_admin = self._get_real_admin_by_model(model)
perm_function = getattr(model_admin, perm_function_name)
if not perm_function(request):
continue
ct = ContentType.objects.get_for_model(model, for_concrete_model=False)
choices.append((ct.id, model._meta.verbose_name))
return choices