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

Respect week overjet in next(). Advances #34.

parent 4531fda5
No related branches found
No related tags found
No related merge requests found
......@@ -83,8 +83,18 @@ class LessonPeriodQuerySet(models.QuerySet):
Q(substitutions__room=room, substitutions__week=models.F('_week')) | Q(room=room))
def next(self, reference: LessonPeriod, offset: Optional[int] = 1) -> LessonPeriod:
id_ = list(self.values_list('id', flat=True)).index(reference.id)
return self.all()[id_+offset]
index = list(self.values_list('id', flat=True)).index(reference.id)
next_index = index + offset
if next_index > self.count() - 1:
next_index %= self.count()
week = reference._week + 1
else:
week = reference._week
return self.extra(
select={'_week': week}
).all()[next_index]
def filter_from_query(self, query_data: QueryDict):
if query_data.get('group', None):
......
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