aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--models.py7
-rw-r--r--views.py2
2 files changed, 8 insertions, 1 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")) \
diff --git a/views.py b/views.py
index 82ef639..23bced4 100644
--- a/views.py
+++ b/views.py
@@ -75,7 +75,7 @@ def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=No
group = get_object_or_404(Group, slug=group_slug, timetable=timetable)
if group.children.count():
- return group_list_common(request, timetable, group.children.order_by("name"))
+ return group_list_common(request, timetable, Group.objects.get_relevant_children(group))
courses = Course.objects.get_courses_for_group(group, begin__gte=start, begin__lt=end) \
.annotate(Max("last_update"))