Skip to content
Snippets Groups Projects
Commit 5559ac94 authored by Julian's avatar Julian
Browse files

Annotate subject and date in the personal note queryset

parent 1c87afd0
No related branches found
No related tags found
1 merge request!111Resolve "[Person overview] Implement multiple selection for marking absences as excused or for deleting"
......@@ -6,6 +6,7 @@ from django.db.models.fields import DateField
from django.db.models.functions import Concat
from django.db.models.query import Prefetch
from django.db.models.query_utils import Q
from django.utils.translation import gettext as _
from calendarweek import CalendarWeek
......@@ -71,6 +72,24 @@ class RegisterObjectRelatedQuerySet(QuerySet):
),
)
def annotate_subject(self) -> QuerySet:
"""
Annotate every personal note/lesson documentation with the subject of the lesson/event.
"""
return self.annotate(
subject=Case(
When(
lesson_period__isnull=False,
then="lesson_period__lesson__subject__name",
),
When(
extra_lesson__isnull=False,
then="extra_lesson__subject__name",
),
default=Value(_("Event"))
)
)
class PersonalNoteManager(CurrentSiteManagerWithoutMigrations):
"""Manager adding specific methods to personal notes."""
......
......@@ -807,7 +807,7 @@ def overview_person(request: HttpRequest, id_: Optional[int] = None) -> HttpResp
)
.order_by(
"-school_term_start", "-order_year", "-order_week", "-order_weekday", "order_period",
)
).annotate_date_range().annotate_subject()
)
personal_note_filter_object = PersonalNoteFilter(request.GET, queryset=personal_notes)
filtered_personal_notes = personal_note_filter_object.qs
......
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