diff options
-rw-r--r-- | models.py | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -16,7 +16,7 @@ from functools import reduce from django.db import models -from django.db.models import Count, Manager, Q, Subquery +from django.db.models import Count, Manager, Q, Subquery, Value from django.db.models.expressions import OuterRef from django.db.models.functions import ExtractWeek, ExtractYear from django.utils import timezone @@ -86,7 +86,8 @@ class GroupManager(Manager): sub = self.get_queryset().filter(timetable=timetable, mention__startswith=OuterRef("mention"), subgroup__startswith=OuterRef("subgroup")) \ - .order_by().values("mention").annotate(c=Count("*")).values("c") + .annotate(v=Value(0)).values("v") \ + .annotate(c=Count("v")).values("c") # fuck Count() return self.get_queryset().filter(*args, timetable=timetable, hidden=False, **criteria) \ .annotate(nbsub=Subquery(sub, output_field=models.IntegerField())) \ |