1 from django.views.generic import ListView, DetailView
2 from django.http import Http404
3 from photo.models import Album, Photo
5 class AlbumListView(ListView):
7 queryset = Album.objects.order_by('-name')
10 class PhotoListView(ListView):
13 order_by = 'order, image'
15 def get_queryset(self):
17 album = Album.objects.get(slug__exact=self.kwargs['slug'])
18 return Photo.objects.filter(album=album)
22 class PhotoView(DetailView):
24 def get_queryset(self, **kwargs):
25 return Photo.objects.get(id=self.kwargs['id']).get_queryset()
27 def get_object(self, **kwargs):
29 photo = Photo.objects.get(id=self.kwargs['id'])
34 def get_context_data(self, **kwargs):
35 context = super(PhotoView, self).get_context_data(**kwargs)
36 album = Album.objects.get(slug__exact=self.kwargs['slug'])
37 photos = Photo.objects.filter(album=album).order_by('order', 'image')
46 if not photo.id == int(self.kwargs['id']):
53 if photo.id == int(self.kwargs['id']):
56 context['next_photo'] = next_photo
57 context['prev_photo'] = prev_photo