aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2017-09-29 14:33:55 +0200
committerAlban Gruin2017-09-29 14:33:55 +0200
commita30de7e84c7c7208f76178586befe5374cd1e02d (patch)
tree9fba9325007d62d2c9081f1ff23b0d4fc56da7eb
parent1d5068de5e4babb8c2c969c626fd1d8b53bc28ea (diff)
Affichage des cours des groupes enfants si le groupe demandé en possède
-rw-r--r--models.py14
1 files 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")