From 2f2f50da9b196e471f06e7104bd1d0d8fe4b247f Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Wed, 26 Sep 2018 16:16:09 +0100
Subject: [PATCH] Ensure that we force missing keys to the back of the queryset

---
 opentech/apply/funds/models/submissions.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/opentech/apply/funds/models/submissions.py b/opentech/apply/funds/models/submissions.py
index 1bc7b0d04..d5029ea50 100644
--- a/opentech/apply/funds/models/submissions.py
+++ b/opentech/apply/funds/models/submissions.py
@@ -61,7 +61,7 @@ class JSONOrderable(models.QuerySet):
                 field = field[1:]
             else:
                 descending = False
-            return OrderBy(RawSQL(f'LOWER({self.json_field}->>%s)', (field,)), descending=descending)
+            return OrderBy(RawSQL(f'LOWER({self.json_field}->>%s)', (field,)), descending=descending, nulls_last=True)
 
         field_ordering = [build_json_order_by(field) for field in field_names]
         return super().order_by(*field_ordering)
-- 
GitLab