Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order of tasks and workplaces #530

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions organizations/migrations/0018_alter_ordering_by_priority.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 4.0.3 on 2022-03-29 08:01

from django.db import migrations
import django.db.models.expressions


class Migration(migrations.Migration):

dependencies = [
("organizations", "0017_make_memberships_unique"),
]

operations = [
migrations.AlterModelOptions(
name="task",
options={
"ordering": (
"facility",
django.db.models.expressions.OrderBy(
django.db.models.expressions.F("priority"),
descending=True,
nulls_last=True,
),
"name",
),
"verbose_name": "task",
"verbose_name_plural": "tasks",
},
),
migrations.AlterModelOptions(
name="workplace",
options={
"ordering": (
"facility",
django.db.models.expressions.OrderBy(
django.db.models.expressions.F("priority"),
descending=True,
nulls_last=True,
),
"name",
),
"verbose_name": "workplace",
"verbose_name_plural": "workplaces",
},
),
]
5 changes: 3 additions & 2 deletions organizations/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# coding: utf-8
from django.db import models
from django.db.models import F
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -326,7 +327,7 @@ class Meta:
verbose_name_plural = _("workplaces")
ordering = (
"facility",
"-priority",
F("priority").desc(nulls_last=True),
"name",
)

Expand Down Expand Up @@ -366,7 +367,7 @@ class Meta:
verbose_name_plural = _("tasks")
ordering = (
"facility",
"-priority",
F("priority").desc(nulls_last=True),
"name",
)

Expand Down
6 changes: 3 additions & 3 deletions scheduler/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.contrib.admin.models import DELETION, LogEntry
from django.contrib.contenttypes.models import ContentType
from django.core.serializers.json import DjangoJSONEncoder
from django.db.models import Count, Prefetch
from django.db.models import Count, F, Prefetch
from django.http import Http404
from django.shortcuts import get_object_or_404
from django.urls import reverse
Expand Down Expand Up @@ -195,8 +195,8 @@ def get_context_data(self, **kwargs):
.annotate(volunteer_count=Count("helpers"))
.order_by(
"facility",
"task__priority",
"workplace__priority",
F("task__priority").desc(nulls_last=True),
christophmeissner marked this conversation as resolved.
Show resolved Hide resolved
F("workplace__priority").desc(nulls_last=True),
"task__name",
"workplace__name",
"ending_time",
Expand Down