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

Add next() method to LessonPeriod QUerySet to get the n-th item before/after a...

Add next() method to LessonPeriod QUerySet to get the n-th item before/after a reference lesson. Advances #34.
parent 5b4f4a9d
No related branches found
No related tags found
No related merge requests found
......@@ -82,6 +82,10 @@ class LessonPeriodQuerySet(models.QuerySet):
return self.filter(
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]
def filter_from_query(self, query_data: QueryDict):
if query_data.get('group', None):
return self.filter_group(int(query_data['group']))
......
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