Browse Source

Reduce the number of queries in /admin/api/channel/

pull/405/head
Pēteris Caune 4 years ago
parent
commit
255d4e7bb7
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
1 changed files with 2 additions and 1 deletions
  1. +2
    -1
      hc/api/admin.py

+ 2
- 1
hc/api/admin.py View File

@ -188,7 +188,7 @@ class ChannelsAdmin(admin.ModelAdmin):
@mark_safe @mark_safe
def project_(self, obj): 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") name = escape(obj.project_name or "Default")
email = escape(obj.email) email = escape(obj.email)
return f"{email} &rsaquo; <a href='{url}'>{name}</a>" return f"{email} &rsaquo; <a href='{url}'>{name}</a>"
@ -196,6 +196,7 @@ class ChannelsAdmin(admin.ModelAdmin):
def get_queryset(self, request): def get_queryset(self, request):
qs = super().get_queryset(request) qs = super().get_queryset(request)
qs = qs.annotate(Count("notification", distinct=True)) 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(project_name=F("project__name"))
qs = qs.annotate(email=F("project__owner__email")) qs = qs.annotate(email=F("project__owner__email"))
return qs return qs


Loading…
Cancel
Save