aboutsummaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
authorAlban Gruin2017-09-28 21:57:54 +0200
committerAlban Gruin2017-09-28 21:57:54 +0200
commita1231e340dbb9236f3804679360c0ab7895ae903 (patch)
tree4d7cbd83b898983526b4b860c4c46aaae1384413 /models.py
parent1c3a7336ad48742da5da56b301496a10a38b92b0 (diff)
Affichage seulement des groupes intéressants pour éviter des clics inutiles :
Si les enfants d’un groupe ont eux-mêmes des enfants, on n’affiche pas ce groupe mais ces enfants.
Diffstat (limited to 'models.py')
-rw-r--r--models.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/models.py b/models.py
index 4be7ef5..0625e34 100644
--- a/models.py
+++ b/models.py
@@ -65,6 +65,13 @@ class Timetable(SlugModel):
class GroupManager(Manager):
+ def get_relevant_children(self, group):
+ parent_in = self.get_queryset().filter(parent=group)
+ return self.get_queryset().filter(Q(parent=group) | Q(parent__in=parent_in)) \
+ .annotate(children_count=Count("children")) \
+ .filter(children_count=0) \
+ .order_by("name")
+
def get_relevant_groups(self, *args, **criteria):
return self.get_queryset().filter(*args, **criteria) \
.annotate(children_count=Count("children")) \