Change the photo metrics count method to be more efficient

This commit is contained in:
loulous27 2025-12-04 01:18:24 +01:00
parent be4ddd132e
commit 239742bba0

View file

@ -22,6 +22,8 @@ from django.views.generic.edit import DeleteView, FormView
from PIL import Image from PIL import Image
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.db import models
from .forms import UploadForm from .forms import UploadForm
from .models import Gallery, Photo, Tag from .models import Gallery, Photo, Tag
@ -162,6 +164,13 @@ class GalleryDetailView(LoginRequiredMixin, DetailView):
if "owner" in self.kwargs: if "owner" in self.kwargs:
context["photos"] = context["photos"].filter(owner__id=self.kwargs["owner"]) context["photos"] = context["photos"].filter(owner__id=self.kwargs["owner"])
#Increment the photo view count
for photo in context["photos"]:
photo.increment_count()
self.object.bulk_update(context["photos"],["increment_count"])
return context return context