From a30de7e84c7c7208f76178586befe5374cd1e02d Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Fri, 29 Sep 2017 14:33:55 +0200 Subject: Affichage des cours des groupes enfants si le groupe demandé en possède --- models.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/models.py b/models.py index 0625e34..cca4df8 100644 --- a/models.py +++ b/models.py @@ -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") -- cgit v1.2.1