1 from django.views.generic import ListView, DetailView
2 from django.http import Http404
3 from models import Album, Photo
5 class AlbumListView(ListView):
7 queryset = Album.objects.order_by('-name')
10 def get_context_data(self, **kwargs):
11 context = super(AlbumListView, self).get_context_data(**kwargs)
14 class PhotoListView(ListView):
17 order_by = 'order, image'
19 def get_queryset(self):
20 album = Album.objects.get(slug__exact=self.kwargs['slug'])
21 return Photo.objects.filter(album=album)
23 class PhotoView(DetailView):
26 def get_object(self, **kwargs):
27 return Photo.objects.get(id=self.kwargs['id'])
29 def get_context_data(self, **kwargs):
30 context = super(PhotoView, self).get_context_data(**kwargs)
31 album = Album.objects.get(slug__exact=self.kwargs['slug'])
32 photos = Photo.objects.filter(album=album).order_by('order', 'image')
41 if not photo.id == int(self.kwargs['id']):
48 if photo.id == int(self.kwargs['id']):
51 context['next_photo'] = next_photo
52 context['prev_photo'] = prev_photo