On 17/04/2009 12:53 PM, James wrote:
> What I've done is store the keys of a users favorite videos in a dict,
> and I try to determine if I should be allowing them to add or remove
> this video from their favorites like this (truncated):
>
> {% for video in video_list %}
>      {% if favorites[video.key] %}
>        ... offer to remove
>      {% endif %}
> {% endfor %}
>
> ... but this of course blows up because the template system can't
> understand favorites[video.key]. I wonder how I should organize this
> data and write the tags so that it works... should I be adding a
> property to each video to mark it as a favorite? I've tried this:
>
> for video in videos:
>    video.favorite = True
>
> but that property (or attribute or whatever it's called) doesn't show
> up in my template as true ... ??

Without seeing the context of the code above, I would guess you would 
need to save() the video for it to show up, but of course that would 
probably not work in your situation either.

A quick google search shows the following snippet should do what you 
want: http://www.djangosnippets.org/snippets/1350/

{% for video in video_list %}
   {% if video.key in favorites.keys %}
      ... offer to remove
   {% endif %}
{% endfor %}


Regards
Darryl

-- 
Darryl Ross
AFOYI, Information Technology Solutions
e: dar...@afoyi.com
p: +61 8 7127 1831
f: +61 8 8425 9607

--~--~---------~--~----~------------~-------~--~----~
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