I have a gallery of images. I've written two views, one pulls the next
image, one the previous. i'd like the views to loop, returning the the
first image when the next method reaches the end an d the last when the
previous method does. The next method loops fine, but the previous
doesn't. Here's the code:

def next(request, picture_id):
        artist_id =
Picture.objects.select_related().get(id=picture_id).artist_id
        try:
                next_picture_id =
Picture.objects.filter(artist__id__exact=artist_id).filter(id__gt=picture_id)[0].id
        except IndexError:
                next_picture_id =
Picture.objects.filter(artist__id__exact=artist_id)[0].id
        picture = get_object_or_404(Picture, pk=next_picture_id)
        return render_to_response('artists/picture.html', {'picture':
picture})

def previous(request, picture_id):
        artist_id =
Picture.objects.select_related().get(id=picture_id).artist_id
        try:
                previous_picture_id =
Picture.objects.filter(artist__id__exact=artist_id).filter(id__lt=picture_id)[0].id
        except IndexError:
                pass
        picture = get_object_or_404(Picture, pk=previous_picture_id)
        return render_to_response('artists/picture.html', {'picture': picture})


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to