From 3920541bb882a78d33b315e9cecfd839a60a3673 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 21 Feb 2018 12:44:35 +0530 Subject: [PATCH] sort documents by title, fall back to created --- pandora/entity/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandora/entity/models.py b/pandora/entity/models.py index 2862896ef..73db13f3b 100644 --- a/pandora/entity/models.py +++ b/pandora/entity/models.py @@ -173,8 +173,13 @@ class Entity(models.Model): elif key == 'sortName': response[key] = self.name_sort elif key == 'documents': + title = get_by_id(settings.CONFIG['documentKeys'], 'title') + if title: + sort_key = 'document__sort__title' + else: + sort_key = 'document__created' response[key] = [ox.toAZ(id_) - for id_, in self.documentproperties.order_by('document__name_sort').values_list('document_id')] + for id_, in self.documentproperties.order_by(sort_key).values_list('document_id')] elif key in self.data: response[key] = self.data[key] return response