Replying to your own posts is so uncool ;)
Here's something that works, I have no idea whether it's efficient or
not - any ideas?.
This code is in my views.py
Essentially what's happening is that I'm adding another attribute
called 'alreadyvoted' to each one of the 'posts'. This is then
available in the template as post.alreadyvoted in this format,
{% for post in posts %}
<h3>{{post.alreadyvoted}}</h3>
{% endfor %}
def index(request):
# get Tags and Posts
tags = Tag.objects.all()
posts = Post.objects.all()
def alreadyvoted(post, voterid):
voters = post.vote_set.all()
for voter in voters:
if voter.id == voterid:
return True
return False
for post in posts:
post.alreadyvoted = alreadyvoted(post, request.user.id)
# as we're using a RequestContext, pretty sure that user variable
is predefined.
context = Context(request, {'debugMe': True, 'tags': tags, 'posts':
posts,
'tagcloud':makeTagCloud(), 'request': request, 'user':
request.user})
return render_to_response('electives/index',
context_instance=context)
Hope this helps someone, and if there's a smarter way of doing this,
I'd really like to know ;)
Cheers,
Tone
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---