From 6676ef2ddbf1ef5a2441158c8e4d9d1007967e5d Mon Sep 17 00:00:00 2001
From: mirabilos <t.glaser@tarent.de>
Date: Sat, 21 Sep 2019 16:48:17 +0200
Subject: [PATCH] Amend function to be able to limit search to same subject.

Advances #34
---
 biscuit/apps/chronos/models.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/biscuit/apps/chronos/models.py b/biscuit/apps/chronos/models.py
index 62ff2474..3aa647eb 100644
--- a/biscuit/apps/chronos/models.py
+++ b/biscuit/apps/chronos/models.py
@@ -187,11 +187,14 @@ class LessonPeriod(SchoolRelated):
     def get_groups(self) -> models.query.QuerySet:
         return self.lesson.groups
 
-    def next_of_same_groups(self) -> Optional[LessonPeriod]:
+    def next_of_same_groups(self, same_subject=False) -> Optional[LessonPeriod]:
         res = LessonPeriod.objects
         # retrieve all LessonPeriods of this group constellation
         for group in self.lesson.groups.all():
             res = res.filter(lesson__groups__pk=group.pk)
+        # same subject?
+        if same_subject:
+            res = res.filter(lesson__subject=self.lesson.subject)
         # sorted by time
         res = res.order_by('period__weekday', 'period__period').distinct()
         # simple list of their PKs
-- 
GitLab