You need to construct your query in the view function to filter for
the comments you want. You can't do these sorts of things from the
template, and that is largely by design so that you keep your logic in
one place: your views, and your presentation in one place: your
template.

On Wed, May 4, 2011 at 7:56 PM, AJ <amanjsi...@gmail.com> wrote:
> I have a Django View that constructs a dictionary to a template. I have seen
> similar questions but no one shows how to access the dictionary value in the
> template using the object pk as the key (in my case the keys are pks of the
> object).
>
> View code that constructs the dict:
>
> comment_uservote = {}
>   if not current_logged_user.is_anonymous():
>     for comment in comments_all:
>         try:
>             co_vote = Vote.objects.get(user=current_logged_user,
> comment=comment)
>             comment_uservote[comment.id] = co_vote.vote
>         except Vote.DoesNotExist:
>             co_vote = ''
>             comment_uservote[comment.id] = co_vote
>
> I have also tried with comment_uservote[str(comment.id)] but this does not
> help either.
>
> Template (that does not work):
>
> {% for comment in comments %}
>   {{comment_uservote.comment.pk}} <!--this does not work-->
> {% enfor %}
>
> However, the following works if I add any comment's pk to
> the comment_uservote.
>
> Template (that works but if a direct substitution):
>
> {% for comment in comments %}
>   {{comment_uservote.16}} <!--this works-->
> {% enfor %}
>
> Appreciate your help. Please let me know if you need something more from me.
> Thanks.
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to