Skip to content
Snippets Groups Projects
Verified Commit 64426488 authored by Nik | Klampfradler's avatar Nik | Klampfradler Committed by mirabilos
Browse files

Actually use the prefetched data from the earlier commit.

This method now must be called only with prefetched data (API).
parent 1843e91e
No related branches found
No related tags found
No related merge requests found
......@@ -130,7 +130,14 @@ class LessonPeriod(SchoolRelated):
def get_substitution(self, week: Optional[int] = None) -> LessonSubstitution:
wanted_week = week or getattr(self, '_week', None) or current_week()
return self.substitutions.filter(week=wanted_week).first()
# We iterate over all substitutions because this can make use of
# prefetching when this model is loaded from outside, in contrast
# to .filter()
for substitution in self.substitutions.all():
if substitution.weeb == wanted_week:
return substitution
return None
def get_subject(self) -> Optional[Subject]:
if self.get_substitution():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment