From 239742bba06445614eca5e51340744fe6eaeda1b Mon Sep 17 00:00:00 2001 From: loulous27 Date: Thu, 4 Dec 2025 01:18:24 +0100 Subject: [PATCH] Change the photo metrics count method to be more efficient --- photologue/views.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/photologue/views.py b/photologue/views.py index 8fd57d3..bf81c3c 100644 --- a/photologue/views.py +++ b/photologue/views.py @@ -22,6 +22,8 @@ from django.views.generic.edit import DeleteView, FormView from PIL import Image from django.contrib.auth import get_user_model +from django.db import models + from .forms import UploadForm from .models import Gallery, Photo, Tag @@ -162,6 +164,13 @@ class GalleryDetailView(LoginRequiredMixin, DetailView): if "owner" in self.kwargs: 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