Skip to content

Commit

Permalink
Merge pull request #565 from christophmeissner/hotfix/562-fix-admin-o…
Browse files Browse the repository at this point in the history
…rdering-by-task-and-workplace

Fix shift/-template admin when ordering by task/workplaces
  • Loading branch information
pitpalme authored Apr 4, 2022
2 parents 11347ee + 51b0fd8 commit de469b5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 14 additions & 3 deletions scheduler/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 14 additions & 3 deletions scheduletemplates/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit de469b5

Please sign in to comment.