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.)

If they have to be in alphabetical order by title and you're going to
show all of them, add something to each one that indicates whether
they've been voted on. Your list could morph into a list of tuples where
the first item is a paper and the second item is a boolean indicating
whether the current user has voted.

Something like:

def display_votes(request):
    all_papers = Paper.objects.all()
    tuple_list = [(p, p.has_voted(request.user)) for p in all_papers]
    ...

Then in the template:

{% for paper_voted in tuple_list %}
{% if paper_voted.1 %}
   stuff if they voted, paper is accessible as paper_voted.0
{% else %}
   stuff if they haven't
{% endif %}

HTH,
Todd

On Sat, 2007-03-24 at 07:55 -0700, Ross Burton wrote:

> My initial implementation was split across the template and the
> model.  In my model:
> 
> class Paper (models.Model):
>     ...
>     def has_voted(paper, user):
>         return paper.vote_set.filter(user__exact = user).count() != 0
> 
> then in the view:
> 
> {% for paper in object_list|dictsort:"title" %}
>   {% if paper.has_voted( TODO ) %}
>     <!-- todo: set different css class -->
> 
> I then discovered that you can't pass arguments to methods in
> templates, so I can't ask the model if the current user has voted.
> 
> Can anyone give any hints on how I can fix this?
> 
> 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 django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to