diff options
-rw-r--r-- | models.py | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -144,11 +144,17 @@ class Room(models.Model): class CourseManager(Manager): def get_courses_for_group(self, group, **criteria): + groups_criteria = [] + if group.subgroup is not None: + groups_criteria.append(Q(groups__subgroup__isnull=True) | \ + Q(groups__subgroup=group.subgroup)) + if group.td is not None: + groups_criteria.append(Q(groups__td__isnull=True) | Q(groups__td=group.td)) + if group.tp is not None: + groups_criteria.append(Q(groups__tp__isnull=True) | Q(groups__tp=group.tp)) + 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), - Q(groups__subgroup__isnull=True) | \ - Q(groups__subgroup=group.subgroup), + .filter(*groups_criteria, groups__mention=group.mention, timetable=group.timetable, **criteria) \ .order_by("begin") |