-def album_view(request, slug):
- try:
- album = Album.objects.get(slug__exact=slug)
- photos = Photo.objects.filter(album=album).order_by('order', 'image')
- except:
- raise Http404
- return django.views.generic.list_detail.object_list(request, photos, paginate_by=20, template_name='photo/photo_index.html', allow_empty=False)
-
-def photo_view(request, slug, id):
- try:
- id = int(id)
- album = Album.objects.get(slug__exact=slug)
+class PhotoListView(ListView):
+ model = Photo
+ paginate_by = 20
+ order_by = 'order, image'
+
+ def get_queryset(self):
+ album = Album.objects.get(slug__exact=self.kwargs['slug'])
+ return Photo.objects.filter(album=album)
+
+class PhotoView(DetailView):
+ model = Photo
+
+ def get_object(self, **kwargs):
+ return Photo.objects.get(id=self.kwargs['id'])
+
+ def get_context_data(self, **kwargs):
+ context = super(PhotoView, self).get_context_data(**kwargs)
+ album = Album.objects.get(slug__exact=self.kwargs['slug'])