X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/79d770e03bde9d600ec6effdcc9c15487ff23897..ce02a06785b4ef96aa7aebc63641883a9ee491d4:/src/picture/models.py?ds=inline diff --git a/src/picture/models.py b/src/picture/models.py index b39661f29..6d8def377 100644 --- a/src/picture/models.py +++ b/src/picture/models.py @@ -12,6 +12,8 @@ from django.core.files.storage import FileSystemStorage from django.utils.datastructures import SortedDict from fnpdjango.utils.text.slughifi import slughifi from ssify import flush_ssi_includes + +from catalogue.models.tag import prefetched_relations from picture import tasks from StringIO import StringIO import jsonfield @@ -101,7 +103,7 @@ class Picture(models.Model): pass class Meta: - ordering = ('sort_key',) + ordering = ('sort_key_author', 'sort_key') verbose_name = _('picture') verbose_name_plural = _('pictures') @@ -127,8 +129,15 @@ class Picture(models.Model): def authors(self): return self.tags.filter(category='author') + def tag_unicode(self, category): + relations = prefetched_relations(self, category) + if relations: + return ', '.join(rel.tag.name for rel in relations) + else: + return ', '.join(self.tags.filter(category=category).values_list('name', flat=True)) + def author_unicode(self): - return ", ".join(self.authors().values_list('name', flat=True)) + return self.tag_unicode('author') @permalink def get_absolute_url(self):