Hi Martin,

> Then i'm trying to display only the first video in base.html (the main
> html template) and all videos in article_detail.html. I can't figure
> out how to display only the first video.. in detail, for loop works
> ok.
>
> This is the code i'm using in base.html (i use templatetag for
> article, to display only ones that have video):
> {% get_article_list as article_list %}
> {% for video in article_list.video.all %}

That won't work from what I understand of your model. If article_list
is a QuerySet, it won't have a .video attribute (that attribute
belongs to a single article.

Furthermore, this for loop wants to loop over all videos, but you said
you only wanted to show the first one.

>   <object>
>   <code for displaying youtube videos>
>   {{ video.0.name }}, {{ video.0.url }}
>   </object>

Here's a solution:

{% get_article_list as article_list %}
{% for article in article_list %}
        {% displayfirstvideo article %}
{% endfor %}

The above assumes that you are trying to display the first video of
*each* article from article_list inside your main template.

Then, create a new template tag called displayfirstvideo:

@register.inclusion_tag('youtube-video.html')
def displayfirstvideo(article):
   video = article.video.all()[0]
   return {'video':video}

Note that this templatetag assumes you've got at least one video in
the article being passed as a parameter. I am sure you can refine that
if necessary.

Create a new template called youtube-video.html in your template path
with something like:

<object>
  <code for displaying youtube videos>
  {{ video.name }}, {{ video.url }}
</object>

-Rajesh D

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