From b24be871658d68f9c336d9ef3c78943d1bc07eb4 Mon Sep 17 00:00:00 2001 From: Christoph Meissner Date: Fri, 1 Apr 2022 10:30:43 +0200 Subject: [PATCH] Fix bug in ShiftTemplateManager Not sure why, but applying `order_by` on the manager's queryset seems to fail, when it tries to order by a field (ie. task or workplace) which is a FK to a model that contains a F-Combinable in its `ordering` property in its Meta object. I guess we might have found a bug in Django. fixes #541 --- scheduletemplates/managers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scheduletemplates/managers.py b/scheduletemplates/managers.py index 661bce02..7b0bf9fb 100644 --- a/scheduletemplates/managers.py +++ b/scheduletemplates/managers.py @@ -1,5 +1,6 @@ # coding: utf-8 from django.db import models +from django.db.models import F class ShiftTemplateManager(models.Manager): @@ -16,8 +17,8 @@ def get_queryset(self): qs = qs.order_by( "schedule_template", - "task", - "workplace", + F("task__priority").desc(nulls_last=True), + F("workplace__priority").desc(nulls_last=True), "starting_time", "-days", "-ending_time",