diff --git a/aleksis/apps/alsijil/views.py b/aleksis/apps/alsijil/views.py index 6ac35f3f59a4050770555563f95e0da16f091c2f..d5f24f9a77c15373d63c407cd310fcdf34df6566 100644 --- a/aleksis/apps/alsijil/views.py +++ b/aleksis/apps/alsijil/views.py @@ -145,7 +145,13 @@ def week_view( instance = get_instance_by_pk(request, year, week, type_, id_) - lesson_periods = LessonPeriod.objects.in_week(wanted_week) + lesson_periods = LessonPeriod.objects.in_week(wanted_week).annotate( + has_documentation=Exists( + LessonDocumentation.objects.filter( + ~Q(topic__exact=""), lesson_period=OuterRef("pk"), week=wanted_week.week + ) + ) + ) if type_ and id_: if isinstance(instance, HttpResponseNotFound): @@ -163,14 +169,6 @@ def week_view( else: lesson_periods = None - lesson_periods = lesson_periods.annotate( - has_documentation=Exists( - LessonDocumentation.objects.filter( - ~Q(topic__exact=""), lesson_period=OuterRef("pk"), week=wanted_week.week - ) - ) - ) - # Add a form to filter the view if type_: initial = {type_.value: instance}