diff --git a/hc/api/management/commands/backfillchannels.py b/hc/api/management/commands/backfillchannels.py index a0ab0a45..bec56968 100644 --- a/hc/api/management/commands/backfillchannels.py +++ b/hc/api/management/commands/backfillchannels.py @@ -13,7 +13,7 @@ class Command(BaseCommand): q = Channel.objects.filter(id=channel.id) try: - n = channel.latest_notification() + n = Notification.objects.filter(channel=channel).latest() q.update(last_notify=n.created, last_error=n.error) total += 1 except Notification.DoesNotExist: diff --git a/hc/api/models.py b/hc/api/models.py index 3d63b8f3..dd308ceb 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -550,9 +550,6 @@ class Channel(models.Model): def icon_path(self): return "img/integrations/%s.png" % self.kind - def latest_notification(self): - return Notification.objects.filter(channel=self).latest() - @property def json(self): return json.loads(self.value) diff --git a/templates/front/channels.html b/templates/front/channels.html index 0b448f32..76355274 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -26,7 +26,6 @@ {% for ch in channels %} - {% with n=ch.latest_notification %} {{ ch.get_kind_display }} @@ -125,13 +124,13 @@ {% endif %} - {% if n %} - {% if n.error %} - - Failed, {{ n.created|naturaltime }} + {% if ch.last_notify %} + {% if ch.last_error %} + + Failed, {{ ch.last_notify|naturaltime }} {% else %} - Delivered, {{ n.created|naturaltime }} + Delivered, {{ ch.last_notify|naturaltime }} {% endif %} {% else %} Never @@ -168,7 +167,6 @@ {% endif %} - {% endwith %} {% endfor %} {% else %}