cached property

This commit is contained in:
j 2025-01-08 18:38:35 +05:30
parent 850ecc97c8
commit 0a5af976b8

View File

@ -8,6 +8,7 @@ from django.utils.html import mark_safe
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from django.db.models.signals import m2m_changed from django.db.models.signals import m2m_changed
from django.dispatch import receiver from django.dispatch import receiver
from django.utils.functional import cached_property
from photologue.models import Photo, Gallery from photologue.models import Photo, Gallery
@ -155,7 +156,7 @@ class Content(models.Model):
if src: if src:
return mark_safe(u'<a href="{}"><img src="{}"></a>'.format(self.get_absolute_url(), src)) return mark_safe(u'<a href="{}"><img src="{}"></a>'.format(self.get_absolute_url(), src))
@property @cached_property
def image_url(self): def image_url(self):
if self.photo: if self.photo:
url = self.photo.image.url url = self.photo.image.url