From 8b72b5f16db50869f65fdef29ad22ffd04523b8f Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 20 Dec 2018 20:29:51 +0100 Subject: Image: form to change main image - fix image in sheets --- ishtar_common/models.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'ishtar_common/models.py') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 6cf2846a6..e1318ef62 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1392,13 +1392,11 @@ class DocumentItem(object): @property def images_without_main_image(self): - if not hasattr(self, 'documents'): - return Document.objects.none() if not hasattr(self, 'main_image'): return self.images return self.documents.filter( image__isnull=False).exclude( - image="", pk=self.main_image.pk).order_by("pk") + image="").exclude(pk=self.main_image.pk).order_by("pk") def get_extra_actions(self, request): """ @@ -3892,6 +3890,11 @@ class Document(OwnPerms, ImageModel, FullSearch, Imported): return Document.objects.filter( pk=self.pk, image__isnull=False).exclude(image='') + @property + def main_image(self): + if self.images.count(): + return self.images.all()[0] + @property def has_related(self): for rel in self.RELATED_MODELS: -- cgit v1.2.3