Fix views & update templates
This commit is contained in:
parent
3029eea1a0
commit
bd12a0abef
5 changed files with 24 additions and 6 deletions
|
@ -3,6 +3,7 @@ from math import floor
|
|||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.db.models import Sum
|
||||
from django.templatetags.static import static
|
||||
from django.urls import reverse
|
||||
from django.utils.text import slugify
|
||||
|
@ -24,8 +25,8 @@ class Album(models.Model):
|
|||
|
||||
@property
|
||||
def photos_views(self):
|
||||
total_views = sum(self.photos.views())
|
||||
return total_views
|
||||
return self.photos.aggregate(total_views=Sum('views'))['total_views'] or 0
|
||||
|
||||
|
||||
@property
|
||||
def cover_image_data(self):
|
||||
|
|
|
@ -69,6 +69,10 @@ class Photo(models.Model):
|
|||
unique_together = ('album', "slug")
|
||||
verbose_name_plural = "Photos"
|
||||
ordering = ('-taken_at',)
|
||||
indexes = [
|
||||
models.Index(fields=['views']),
|
||||
models.Index(fields=['likes']),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.slug} ({self.orientation}) {self.is_favorite}'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue