On Mar 25, 3:28 pm, "Ross Burton" <[EMAIL PROTECTED]> wrote:
> > What is it you want to do with the ones they've voted on vs. haven't? If
> > you're going to hide the ones they've already voted on, just write a
> > query in the view method that only returns those and pass that to the
> > context. (Note: the view method, not the template. See Ivan's response.)
>
> I thought I'd go this route -- it seemed simplier and more useful.
> However, I can't seem to work out the query. My initial attempt:
>
> def pending(request):
> return object_list(request,
> Paper.objects.exclude(vote__user=request.user))
>
> However this appears to joining Paper and Vote, filtering out the rows
> where I voted, and then showing the rows remaining (which leads to
> duplicates).
>
> What would the correct filter be for all Papers which don't have a
> related Vote object with a given user field?
Ok so I'm a fool. I now have this which works:
def pending(request):
all_papers = Paper.objects.all()
tuple_list = [p for p in all_papers if not
p.has_voted(request.user)]
return render_to_response('papers/paper_list.html',
{ 'object_list': tuple_list })
Would there be any theoretical advantage in using a generator to
filter the list of all papers as it is iterated?
Thanks,
Ross
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---