From 255d4e7bb79f312770c18ac269a3e5d09c48798f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Thu, 16 Jul 2020 16:15:58 +0300 Subject: [PATCH] Reduce the number of queries in /admin/api/channel/ --- hc/api/admin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hc/api/admin.py b/hc/api/admin.py index ade82b30..d7920a0e 100644 --- a/hc/api/admin.py +++ b/hc/api/admin.py @@ -188,7 +188,7 @@ class ChannelsAdmin(admin.ModelAdmin): @mark_safe def project_(self, obj): - url = reverse("hc-checks", args=[obj.project.code]) + url = reverse("hc-checks", args=[obj.project_code]) name = escape(obj.project_name or "Default") email = escape(obj.email) return f"{email} › {name}" @@ -196,6 +196,7 @@ class ChannelsAdmin(admin.ModelAdmin): def get_queryset(self, request): qs = super().get_queryset(request) qs = qs.annotate(Count("notification", distinct=True)) + qs = qs.annotate(project_code=F("project__code")) qs = qs.annotate(project_name=F("project__name")) qs = qs.annotate(email=F("project__owner__email")) return qs