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

Use distincts for affected querysets to prevent double entries

(cherry picked from commit 4c705a68)
parent b0065259
No related branches found
No related tags found
1 merge request!187Prepare release 2.0b3
......@@ -19,6 +19,7 @@ Fixed
* Preference section verbose names were displayed in server language and not
user language (fixed by using gettext_lazy).
* Affected groups and persons in substitutions list were displayed multiple times.
`2.0b2` - 2021-06-02
--------------------
......
......@@ -545,7 +545,7 @@ class LessonSubstitutionQuerySet(LessonDataQuerySet):
"""Return all lessons which are affected by selected substitutions."""
from .models import Lesson # noaq
return Lesson.objects.filter(lesson_periods__substitutions__in=self)
return Lesson.objects.filter(lesson_periods__substitutions__in=self).distinct()
def affected_teachers(self):
"""Get affected teachers.
......@@ -553,13 +553,21 @@ class LessonSubstitutionQuerySet(LessonDataQuerySet):
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)
).order_by("short_name")
return (
Person.objects.filter(
Q(lessons_as_teacher__in=self.affected_lessons()) | Q(lesson_substitutions__in=self)
)
.distinct()
.order_by("short_name")
)
def affected_groups(self):
"""Return all groups which are affected by selected substitutions."""
return Group.objects.filter(lessons__in=self.affected_lessons()).order_by("short_name")
return (
Group.objects.filter(lessons__in=self.affected_lessons())
.distinct()
.order_by("short_name")
)
class DateRangeQuerySetMixin:
......
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