diff options
-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() |