Freshest alerts first.
[redakcja.git] / src / alerts / templatetags / alerts.py
1 from django.template import Library
2 from django.db.models import Max
3 from ..models import Alert
4
5
6 register = Library()
7
8 @register.simple_tag
9 def get_alerts():
10     return {
11         'count': Alert.objects.all().count(),
12         'items': Alert.objects.all().annotate(
13             m=Max('book__chunk__head__created_at')
14         ).order_by('-m')[:20],
15     }