from django.template import Library
+from django.db.models import Max
from ..models import Alert
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],
}