aboutsummaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
authorAlban Gruin2017-10-27 09:37:25 +0200
committerAlban Gruin2017-10-27 09:37:25 +0200
commit827641acd0b2c64feb704bae989b139458a3d0ca (patch)
tree101bd04710f53c60194b4dc28aa1f408a94dc765 /models.py
parent12184b16e97d9f5c6c99d6bfe79b1e5c53464fb3 (diff)
Fonction pour récupérer les parents d’un groupe
Diffstat (limited to 'models.py')
-rw-r--r--models.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/models.py b/models.py
index 74fab9e..c546737 100644
--- a/models.py
+++ b/models.py
@@ -70,11 +70,21 @@ class Timetable(SlugModel):
class GroupManager(Manager):
+ def get_parents(self, group):
+ groups_criteria = Q(subgroup__isnull=True) | \
+ reduce(lambda x, y: x | y,
+ [Q(subgroup=group.subgroup[:i])
+ for i in range(1, len(group.subgroup) + 1)])
+
+ return self.get_queryset().filter(groups_criteria, mention=group.mention,
+ timetable=group.timetable)
+
def get_relevant_groups(self, timetable, *args, **criteria):
sub = Group.objects.filter(timetable=timetable,mention=OuterRef("mention"),
subgroup__startswith=OuterRef("subgroup")) \
.order_by().values("mention").annotate(c=Count("*")).values("c")
- return Group.objects.filter(*args, timetable=timetable, hidden=False, **criteria) \
+
+ return self.get_queryset().filter(*args, timetable=timetable, hidden=False, **criteria) \
.annotate(nbsub=Subquery(sub, output_field=models.IntegerField())) \
.filter(nbsub=1).order_by("name")
@@ -146,15 +156,8 @@ class Room(models.Model):
class CourseManager(Manager):
def get_courses_for_group(self, group, **criteria):
- groups_criteria = reduce(lambda x, y: x | y,
- [Q(groups__subgroup=group.subgroup[:i])
- for i in range(1, len(group.subgroup) + 1)]) | \
- Q(groups__subgroup__isnull=True)
-
return self.get_queryset() \
- .filter(groups_criteria,
- groups__mention=group.mention,
- timetable=group.timetable, **criteria) \
+ .filter(groups__in=Group.objects.get_parents(group), **criteria) \
.order_by("begin")
def get_weeks(self, **criteria):