When i write out just {{video}} it outputs the id of the object, but
when i try {{video.id}} or {{video.title}} i get nothing.

On Feb 1, 11:03 am, grimmus <graham.col...@gmail.com> wrote:
> I am still experiencing issues with this.
>
> Anyone any idea what i am doing wrong ?
>
> Thanks !
>
> On Jan 28, 3:28 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
>
> > On Jan 28, 2:18 pm, grimmus <graham.col...@gmail.com> wrote:
>
> > > Thanks for the reply. I am having some issues outputting the fields
> > > now though.
>
> > > It seems 4 objects are being returned alright but when i try and
> > > output a value it's blank.
>
> > > top_videos = {}
>
> > >     for i in xrange(1,6):
> > >         videos =Video.objects.filter(category=i).order_by('-
> > > hit_count')
> > >         if videos:
> > >             top_videos[i] = videos[0]
>
> > >     t = loader.get_template('home/display.html')
> > >     c = RequestContext(request,{
> > >         'top_videos': top_videos
> > >     })
> > >     return HttpResponse(t.render(c))
>
> > > and in my template:
>
> > > {% forvideoin top_videos %}
> > >    {{video.title}}
> > > {% endfor %}
>
> > > Any ideas what i am doing wrong ?
>
> > For some reason, Gabriel's solution defined top_videos as a
> > dictionary, so you would need to iterate through it as {% for
> > category_id,videoin top_videos.items %}.
>
> > A better way would be to define it as a list:
> >     top_videos = []
> >     for i in xrange(1,6):
> >         videos =Video.objects.filter(category=i).order_by('-
> > hit_count')
> >         if videos:
> >             top_videos.append(videos[0])
>
> > I must say, when I originally saw your post, I thought there must be
> > an even simpler solution that gets to the topvideoin each category
> > in a single query, using aggregation. But I've been unable to come up
> > with the correct way of doing it.
> > --
> > DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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