From 6e2aaaf50c194934287f665be17ea6cdb4f93027 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Fri, 24 May 2019 17:08:22 +0100 Subject: [PATCH] GH-1191: Make sure the review ordering is correct --- opentech/apply/funds/models/submissions.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/opentech/apply/funds/models/submissions.py b/opentech/apply/funds/models/submissions.py index 2ca3bba01..661bb355b 100644 --- a/opentech/apply/funds/models/submissions.py +++ b/opentech/apply/funds/models/submissions.py @@ -802,11 +802,17 @@ class AssignedReviewersQuerySet(models.QuerySet): type_order=models.Case( *ordering, output_field=models.IntegerField(), + ), + has_review=models.Case( + models.When(review__isnull=True, then=models.Value(1)), + models.When(review__is_draft=True, then=models.Value(1)), + default=models.Value(0), + output_field=models.IntegerField(), ) ).order_by( - F('role__order').asc(nulls_last=True), 'type_order', - F('review__pk').asc(nulls_last=True), + 'has_review', + F('role__order').asc(nulls_last=True), ).select_related( 'reviewer', 'role', -- GitLab