From 10b6900c49a1d24e944f73119911bd17509c8772 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 23 May 2022 12:12:16 +0200 Subject: [PATCH] Freshest alerts first. --- src/alerts/templatetags/alerts.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/alerts/templatetags/alerts.py b/src/alerts/templatetags/alerts.py index cbab9de2..e4432172 100644 --- a/src/alerts/templatetags/alerts.py +++ b/src/alerts/templatetags/alerts.py @@ -1,4 +1,5 @@ from django.template import Library +from django.db.models import Max from ..models import Alert @@ -8,5 +9,7 @@ register = Library() def get_alerts(): return { 'count': Alert.objects.all().count(), - 'items': Alert.objects.all()[:20], + 'items': Alert.objects.all().annotate( + m=Max('book__chunk__head__created_at') + ).order_by('-m')[:20], } -- 2.20.1