From ebb7c3bf0dc3eef2efa3f4add60ccfc7dc063248 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sat, 28 Jan 2017 13:20:23 +0100 Subject: Traitement des semaines avec un group by, semblant diviser par deux le temps de traitement --- models.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'models.py') diff --git a/models.py b/models.py index bcd9215..aa7be24 100644 --- a/models.py +++ b/models.py @@ -119,6 +119,7 @@ class Room(models.Model): class CourseManager(GroupedManager): def __get_weeks(self, qs): extractYear = ExtractYear("begin") + qs = qs.group_by("groups", "year", "week").order_by("groups__name", "year", "week") if connection.vendor == "postgresql": return qs.annotate(week=ExtractWeek("begin"), year=extractYear) @@ -128,11 +129,8 @@ class CourseManager(GroupedManager): def get_courses_for_group(self, group, **filters): return self.get_queryset().filter(Q(groups__td__isnull=True) | Q(groups__td=group.td), Q(groups__tp__isnull=True) | Q(groups__tp=group.tp), groups__mention=group.mention, groups__subgroup=group.subgroup, **filters).order_by("begin") - def get_weeks(self): - return self.__get_weeks(self.get_queryset()) - - def get_courses_for_group_and_weeks(self, group, **filters): - qs = self.get_courses_for_group(group, **filters) + def get_weeks(self, **criteria): + qs = self.get_queryset().filter(**criteria) return self.__get_weeks(qs) -- cgit v1.2.1