Hi Sasha,
On Tue, 2006-07-18 at 06:26 +0000, sasha wrote:
> I'm sorry this is the method I've been trying to use
>
> 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:
> previous_picture_id =
> Picture.objects.filter(artist__id__exact=artist_id).order_by("-id")[0].id
I would guess this is going to be the problem: you are first filtering
on an id__exact condition, which will restrict your queryset to exactly
one element -- the current one -- and then trying to extract the first
guy from that list.
You probably want:
Picture.objects.order_by("-id")[0]
Similarly, in the first case queryset you are filtering on two
conditions and the first one is an exact match on a unique key. So
remove the artist__id__exact filter condition in both cases and it
should work.
[That was much easier to understand when I could stare at some code.
Thanks for the extra information. :-) ]
Regards,
Malcolm
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---