From 4c705a68d687a5417b29a6ee56aa23c627f31964 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Sun, 6 Jun 2021 14:35:30 +0200 Subject: [PATCH] Use distincts for affected querysets to prevent double entries --- CHANGELOG.rst | 8 ++++++++ aleksis/apps/chronos/managers.py | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5fd93ff2..f6a5e6b3 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,14 @@ All notable changes to this project will be documented in this file. The format is based on `Keep a Changelog`_, and this project adheres to `Semantic Versioning`_. +Unreleased +---------- + +Fixed +~~~~~ + +* Affected groups and persons in substitutions list were displayed multiple times. + `2.0b2` - 2021-06-02 -------------------- diff --git a/aleksis/apps/chronos/managers.py b/aleksis/apps/chronos/managers.py index 82021ef4..042d91a6 100644 --- a/aleksis/apps/chronos/managers.py +++ b/aleksis/apps/chronos/managers.py @@ -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: -- GitLab