diff options
author | Alban Gruin | 2017-11-01 15:17:35 +0100 |
---|---|---|
committer | Alban Gruin | 2017-11-01 15:17:35 +0100 |
commit | 912f3cca24da9d870aa191348fef901adcd55b7d (patch) | |
tree | 2566aff8bb231c005d9799f611e89f820b193ba7 | |
parent | bafa5f07a4e1b5c2cc2bb234ad2f12929a983025 (diff) |
get_parents() sélectionne aussi les groupes enfants dont le
sous-groupe commence par la même chaîne que celui du groupe passé en
paramètre.
Correction cosmétique du code.
-rw-r--r-- | models.py | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -71,7 +71,7 @@ class Timetable(SlugModel): class GroupManager(Manager): def get_parents(self, group): - groups_criteria = Q(subgroup__isnull=True) | \ + groups_criteria = Q(subgroup__isnull=True) | Q(subgroup__startswith=group.subgroup) | \ reduce(lambda x, y: x | y, [Q(subgroup=group.subgroup[:i]) for i in range(1, len(group.subgroup) + 1)]) @@ -80,7 +80,7 @@ class GroupManager(Manager): timetable=group.timetable) def get_relevant_groups(self, timetable, *args, **criteria): - sub = Group.objects.filter(timetable=timetable,mention=OuterRef("mention"), + sub = Group.objects.filter(timetable=timetable, mention=OuterRef("mention"), subgroup__startswith=OuterRef("subgroup")) \ .order_by().values("mention").annotate(c=Count("*")).values("c") |