diff --git a/scheduler/admin.py b/scheduler/admin.py index a880de25..0f78ecfc 100644 --- a/scheduler/admin.py +++ b/scheduler/admin.py @@ -3,7 +3,7 @@ from django import forms from django.contrib import admin from django.core.exceptions import ValidationError -from django.db.models import Count +from django.db.models import Count, F from django.utils import timezone from django.utils.html import format_html, mark_safe from django.utils.translation import gettext_lazy as _ @@ -150,9 +150,20 @@ def _format_username(user): get_volunteer_names.short_description = _("volunteers") get_volunteer_names.allow_tags = True + @admin.display(ordering=F("task").desc(nulls_last=True), description=_("task")) + def get_task(self, obj): + return obj.task + + @admin.display( + ordering=F("workplace").desc(nulls_last=True), + description=_("workplace"), + ) + def get_workplace(self, obj): + return obj.workplace + list_display = ( - "task", - "workplace", + "get_task", + "get_workplace", "facility", "starting_time", "ending_time", diff --git a/scheduletemplates/admin.py b/scheduletemplates/admin.py index 46bfa207..e4848145 100644 --- a/scheduletemplates/admin.py +++ b/scheduletemplates/admin.py @@ -3,7 +3,7 @@ from django import forms from django.contrib import admin, messages from django.core.exceptions import ValidationError -from django.db.models import Count, Min, Sum +from django.db.models import Count, F, Min, Sum from django.forms import DateInput, TimeInput from django.http import HttpResponseForbidden from django.shortcuts import get_object_or_404, redirect @@ -383,13 +383,24 @@ def get_facility(self, obj): get_facility.short_description = _("facility") get_facility.admin_order_field = "schedule_template__facility" + @admin.display(ordering=F("task").desc(nulls_last=True), description=_("task")) + def get_task(self, obj): + return obj.task + + @admin.display( + ordering=F("workplace").desc(nulls_last=True), + description=_("workplace"), + ) + def get_workplace(self, obj): + return obj.workplace + list_display = ( "get_edit_link", "get_facility", "schedule_template", "slots", - "task", - "workplace", + "get_task", + "get_workplace", "starting_time", "ending_time", "members_only",