sort documents by title, fall back to created

This commit is contained in:
j 2018-02-21 12:44:35 +05:30
parent 88d47eba6b
commit 3920541bb8
1 changed files with 6 additions and 1 deletions

View File

@ -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