Skip to content

Commit

Permalink
Merge pull request #445 from safaariman/master
Browse files Browse the repository at this point in the history
Performance improvement on parentadmin
  • Loading branch information
chrisglass committed Aug 14, 2020
2 parents d95347b + 8b35063 commit 378e30c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions polymorphic/admin/parentadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ def get_child_type_choices(self, request, action):
"""
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

Expand Down

0 comments on commit 378e30c

Please sign in to comment.