From 93203b4489ceb4cfdc034864b2a78ed6dec17112 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Thu, 18 Jun 2020 22:09:20 +0200
Subject: [PATCH] Move annotate before union because annotating works only
 before union

---
 aleksis/apps/alsijil/views.py | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/aleksis/apps/alsijil/views.py b/aleksis/apps/alsijil/views.py
index 6ac35f3f5..d5f24f9a7 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}
-- 
GitLab