Filter gallery by photo owner

This commit is contained in:
Alexandre Iooss 2021-10-13 17:05:29 +02:00
parent 740cbc9df0
commit cc3ba4a492
3 changed files with 40 additions and 3 deletions

View file

@ -43,6 +43,29 @@ class CustomGalleryYearArchiveView(GalleryYearArchiveView):
uses_datetime_field = False # Fix related object access
class CustomGalleryDetailView(DetailView):
"""
Custom gallery detail view to filter on photo owner
"""
queryset = Gallery.objects.on_site().is_public()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['photos'] = self.object.public()
# List owners
context['owners'] = []
for photo in context['photos']:
if photo.extented.owner not in context['owners']:
context['owners'].append(photo.extented.owner)
# Filter on owner
if 'owner' in self.kwargs:
context['photos'] = context['photos'].filter(extented__owner__id=self.kwargs['owner'])
return context
class GalleryDownload(LoginRequiredMixin, DetailView):
model = Gallery