Skip to content
Snippets Groups Projects
Verified Commit 8cbb193c authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Fix queries for affected teachers and groups in order to show them only one time in the list

Close #67
parent 455c9d1b
No related branches found
No related tags found
No related merge requests found
...@@ -254,12 +254,17 @@ class LessonSubstitutionQuerySet(LessonDataQuerySet): ...@@ -254,12 +254,17 @@ class LessonSubstitutionQuerySet(LessonDataQuerySet):
def affected_teachers(self): def affected_teachers(self):
""" Return all teachers which are affected by selected substitutions (as substituted or substituting) """ """ Return all teachers which are affected by selected substitutions (as substituted or substituting) """
return Person.objects.filter(Q(lessons_as_teacher__in=self.affected_lessons()) | Q(lesson_substitutions__in=self)) return Person.objects.filter(
Q(lessons_as_teacher__in=self.affected_lessons())
| Q(lesson_substitutions__in=self)
).annotate(lessons_count=Count("lessons_as_teacher"))
def affected_groups(self): def affected_groups(self):
""" Return all groups which are affected by selected substitutions """ """ Return all groups which are affected by selected substitutions """
return Group.objects.filter(lessons__in=self.affected_lessons()) return Group.objects.filter(lessons__in=self.affected_lessons()).annotate(
lessons_count=Count("lessons")
)
class TimePeriod(models.Model): class TimePeriod(models.Model):
......
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