forked from GithubBackups/healthchecks
In channels admin, don't show the notification counts, querying it is too expensive.
This commit is contained in:
parent
c7af52637a
commit
c75a37570e
@ -147,7 +147,7 @@ class ProfileAdmin(admin.ModelAdmin):
|
|||||||
@mark_safe
|
@mark_safe
|
||||||
def checks(self, obj):
|
def checks(self, obj):
|
||||||
s = "%d of %d" % (obj.num_checks, obj.check_limit)
|
s = "%d of %d" % (obj.num_checks, obj.check_limit)
|
||||||
if obj.num_checks > 10:
|
if obj.num_checks > 1:
|
||||||
s = "<b>%s</b>" % s
|
s = "<b>%s</b>" % s
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
@ -175,14 +175,7 @@ class ChannelsAdmin(admin.ModelAdmin):
|
|||||||
css = {"all": ("css/admin/channels.css",)}
|
css = {"all": ("css/admin/channels.css",)}
|
||||||
|
|
||||||
search_fields = ["value", "project__owner__email"]
|
search_fields = ["value", "project__owner__email"]
|
||||||
list_display = (
|
list_display = ("id", "transport", "name", "project_", "value", "ok")
|
||||||
"id",
|
|
||||||
"kind_",
|
|
||||||
"name",
|
|
||||||
"project_",
|
|
||||||
"value",
|
|
||||||
"num_notifications",
|
|
||||||
)
|
|
||||||
list_filter = ("kind",)
|
list_filter = ("kind",)
|
||||||
raw_id_fields = ("project", "checks")
|
raw_id_fields = ("project", "checks")
|
||||||
|
|
||||||
@ -195,20 +188,23 @@ 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(project_code=F("project__code"))
|
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
|
||||||
|
|
||||||
@mark_safe
|
@mark_safe
|
||||||
def kind_(self, obj):
|
def transport(self, obj):
|
||||||
return f'<span class="icon-{ obj.kind }"></span> {obj.kind}'
|
note = ""
|
||||||
|
if obj.kind == "email" and not obj.email_verified:
|
||||||
|
note = " (not verified)"
|
||||||
|
|
||||||
def num_notifications(self, obj):
|
return f'<span class="icon-{ obj.kind }"></span> {obj.kind}{note}'
|
||||||
return obj.notification__count
|
|
||||||
|
|
||||||
num_notifications.short_description = "# Notifications"
|
def ok(self, obj):
|
||||||
|
return False if obj.last_error else True
|
||||||
|
|
||||||
|
ok.boolean = True
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Notification)
|
@admin.register(Notification)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user