muistox/gallery/views.py

46 lines
1.1 KiB
Python
Raw Normal View History

2025-01-04 20:04:20 +02:00
from django.shortcuts import get_object_or_404, redirect, render
from django.views.generic import DetailView, ListView, TemplateView
2025-01-05 17:26:09 +02:00
from .models import Album, Photo
2024-12-28 12:21:29 +02:00
# Create your views here.
2024-12-28 14:14:21 +02:00
class Main(TemplateView):
2025-01-04 20:04:20 +02:00
template_name = "gallery/main.html"
class AlbumsList(ListView):
model = Album
template_name = 'gallery/album_list.html'
queryset = Album.objects.filter(is_public=True)
ordering = ['-album_date']
class AlbumDetail(DetailView):
model = Album
template_name = 'gallery/album_detail.html'
def get_object(self, queryset=None):
2025-01-05 17:26:09 +02:00
return get_object_or_404(Album, slug=self.kwargs.get('album_slug'))
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['photos'] = self.object.photos.all()
return context
class PhotoDetail(DetailView):
model = Photo
template_name = 'gallery/photo_detail.html'
def get_object(self, queryset=None):
return get_object_or_404(Photo, slug=self.kwargs.get('photo_slug'))
2025-01-05 22:34:39 +02:00
class PhotosList(ListView):
model = Photo
paginate_by = 30