diff options
Diffstat (limited to 'app/photos/models.py')
-rw-r--r-- | app/photos/models.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/photos/models.py b/app/photos/models.py index eb4b55e..2e022e2 100644 --- a/app/photos/models.py +++ b/app/photos/models.py @@ -7,6 +7,7 @@ from django.core.exceptions import ValidationError from django.contrib.gis.db import models from django.contrib.sitemaps import Sitemap from django.utils.encoding import force_text +from django.utils.functional import cached_property from django.urls import reverse from django.apps import apps from django.utils.html import format_html @@ -111,6 +112,32 @@ class LuxImage(models.Model): def get_image_ext(self): return self.image.url[-3:] + @cached_property + def get_featured_jrnl(self): + ''' cached version of getting the primary image for archive page''' + return "%s%s/%s_%s.%s" % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.get_image_name(), 'featured_jrnl', self.get_image_ext()) + + @cached_property + def get_picwide_sm(self): + ''' cached version of getting the second image for archive page''' + return "%s%s/%s_%s.%s" % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.get_image_name(), 'picwide-sm', self.get_image_ext()) + + @cached_property + def get_srcset(self): + srcset = "" + for size in self.sizes.all(): + srcset += "%s%s/%s_%s.%s %sw, " % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.get_image_name(), size.name, self.get_image_ext(), size.width) + return srcset + + @cached_property + def get_src(self): + src = "" + if self.sizes.all().count() > 1: + src += "%s%s/%s_%s.%s" % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.get_image_name(), 'picwide-med', self.get_image_ext()) + else: + src += "%s%s/%s_%s.%s" % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.get_image_name(), [size.name for size in self.sizes.all()], self.get_image_ext()) + return src + def get_image_by_size(self, size="original"): base = self.get_image_name() if size == "admin_insert": @@ -136,6 +163,9 @@ class LuxImage(models.Model): return format_html('<a href="%s"><img src="%s"></a>' % (self.get_image_by_size(), self.get_image_by_size("tn"))) admin_thumbnail.short_description = 'Thumbnail' + def get_sizes(self): + return self.sizes.all() + @property def latitude(self): return self.point.y |