diff options
author | Alban Gruin | 2017-02-11 13:47:38 +0100 |
---|---|---|
committer | Alban Gruin | 2017-02-11 13:47:38 +0100 |
commit | ff25e2dc285c423f4c40a83deb89a56ee62b15a9 (patch) | |
tree | 888b5189c582371417ddcba02cbf5e883fa0e36e | |
parent | 26a132d5d1fdb7fc9da827bbc9d5e409834fb954 (diff) |
Nettoyage du code de CourseManagerdev/db-groupby
-rw-r--r-- | models.py | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -144,21 +144,17 @@ class Room(models.Model): class CourseManager(Manager): - def __get_weeks(self, qs): - qs = qs.order_by("groups__name", "year", "week").annotate(_=Count(("groups", "year", "week", "begin")), year=ExtractYear("begin")) + 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, timetable=group.timetable, **filters).order_by("begin") + + def get_weeks(self, **criteria): + qs = self.get_queryset().filter(**criteria).order_by("groups__name", "year", "week").annotate(_=Count(("groups", "year", "week", "begin")), year=ExtractYear("begin")) if connection.vendor == "postgresql": return qs.annotate(week=ExtractWeek("begin")) else: return qs.annotate(week=RawSQL("""cast(strftime("%%W", "begin") as integer)""", [])) - 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, timetable=group.timetable, **filters).order_by("begin") - - def get_weeks(self, **criteria): - qs = self.get_queryset().filter(**criteria) - return self.__get_weeks(qs) - class Course(models.Model): objects = CourseManager() |