Optimize templates & clean code

This commit is contained in:
Nyymix 2025-04-26 20:39:57 +03:00
parent 0c1c888547
commit 86d9ca5066
11 changed files with 98 additions and 48 deletions

View file

@ -38,10 +38,10 @@ class Photo(models.Model):
@property
def orientation(self):
return "Portrait" if self.height > self.width else "Landscape"
@property
def aspect_ratio(self):
return self.width / self.height
return self.width / self.height
def save(self, *args, **kwargs):
if not self.slug:
@ -59,7 +59,7 @@ class Photo(models.Model):
def get_next(self):
return self.__class__.objects.filter(taken_at__gt=self.taken_at, album=self.album).order_by('taken_at').first()
def get_prev(self):
return self.__class__.objects.filter(taken_at__lt=self.taken_at, album=self.album).order_by('-taken_at').first()
@ -77,7 +77,6 @@ class Photo(models.Model):
def __str__(self):
return f'{self.slug} ({self.orientation}) {self.is_favorite}'
@receiver(post_save, sender=Photo)
@ -95,4 +94,4 @@ def handle_photo_creation(sender, instance, created, **kwargs):
# Aseta cover, jos albumilla ei ole vielä sellaista
if instance.album and not instance.album.cover:
instance.album.cover = instance
instance.album.save(update_fields=['cover'])
instance.album.save(update_fields=['cover'])