From 70e09b7c5264da8f8f845a374028f6f02c1cef05 Mon Sep 17 00:00:00 2001 From: lxf Date: Mon, 21 Dec 2020 14:35:36 -0500 Subject: fixed a bug in src and srcset functions on luximage --- app/media/models.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'app/media') diff --git a/app/media/models.py b/app/media/models.py index b9437f1..d7b79c6 100644 --- a/app/media/models.py +++ b/app/media/models.py @@ -122,7 +122,7 @@ class LuxImage(models.Model): def get_image_filename(self): return os.path.basename(self.image.path) - @cached_property + @property def get_srcset(self): srcset = "" length = len(self.sizes.all()) @@ -135,13 +135,14 @@ class LuxImage(models.Model): loopnum = loopnum+1 return srcset - @cached_property + @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.image_name, 'picwide-med', self.image_ext) + src = self.get_image_url_by_size('picwide-med') else: - src += "%s%s/%s_%s.%s" % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.image_name, [size.name for size in self.sizes.all()], self.image_ext) + size = "".join(size.name for size in self.sizes.all()) + src = self.get_image_url_by_size(size) return src def get_image_url_by_size(self, size="original"): -- cgit v1.2.3-70-g09d2