aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2017-11-16 13:34:30 +0100
committerAlban Gruin2017-11-16 13:34:30 +0100
commit4fdb7f6263d6463ac2099c383b1221789d28e42e (patch)
tree2f9268f3b071120db01106dba05a486faebeae87
parent0c2937bab77280beaabe7d53a77c848848845950 (diff)
Correction des erreurs lorsqu’un groupe n’a pas de sous-groupe
-rw-r--r--models.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/models.py b/models.py
index b9f1ba7..a90e9da 100644
--- a/models.py
+++ b/models.py
@@ -72,10 +72,12 @@ class Timetable(SlugModel):
class GroupManager(Manager):
def get_parents(self, group):
- groups_criteria = Q(subgroup="") | 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)])
+ groups_criteria = Q(subgroup="") | Q(subgroup__startswith=group.subgroup)
+
+ if len(group.subgroup) != 0:
+ groups_criteria |= 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)