Change the photo metrics count method to be more efficient
This commit is contained in:
parent
be4ddd132e
commit
239742bba0
1 changed files with 9 additions and 0 deletions
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue