Hi Rajesh,

thanks for your quick reply. I don't really understand your point but
i'll try to explain mine:
get_article_list is a queryset, it filters live articles and compares
them to todays date and returns only the ones that are in future. But
the thing is, before manytomany i had video field as foreignkey to
Video model and stuff worked - i used my templatetag and add
attributes (in for loop) .video, .body, .pub_date.
I really don't understand why this doesn't work - i thought i could
just loop through videos of an article and just display the first one
(it's like a thumbnail for an article).

I'm looking at your sample code:
@register.inclusion_tag('youtube-video.html')
def displayfirstvideo(article):
   video = article.video.all()[0]
   return {'video':video}

article.video.all() - isn't "video" here a manager? In my manager i'm
just filtering articles that have videos, like
Article.live.filter(video__isnull=False).. and when i add 2 videos to
an article, templatetag doesn't return one article with 2 videos, ut 2
same articles with 2 videos..
So my question here is.. what am i doing wrong? I just need a little
guide where to look.

Thanks for your help in advance,
Martin

On 8 feb., 18:55, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> 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