From: Radek Czajka Date: Mon, 23 May 2022 10:12:16 +0000 (+0200) Subject: Freshest alerts first. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/10b6900c49a1d24e944f73119911bd17509c8772?ds=sidebyside Freshest alerts first. --- 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], }