On Jan 15, 1:47 pm, grimmus <[email protected]> wrote:
> Hi,
>
> I have a view that gets the latest videos:
>
> videos = Video.objects.filter(category=category,active=1).order_by
> ('-hit_count')
>
> In my template i would like the first result to appear in the primary
> block and the other results to appear in the secondary block
>
> {% block primary %}
> SHOW FIRST VIDEO HERE
> {% endblock %}
>
> {% block secondary %}
> <ul>
> {% for video in videos %}
> <li>
> SHOW OTHER VIDEOS HERE
> </li>
> {% endfor %}
> </ul>
> {% endblock %}
>
> How could i show the first result in 'block primary' without using a
> for loop and how could i begin the loop in 'block secondary' at the
> second place (i.e. not showing the first video here) ?
>
> Thanks for any tips, i hope i have been clear.
{{ videos.0 }}
{{ videos|slice:"1:" }}
Note this will make two separate queries to the database. You might
want to call list() on the queryset in the view to force it to
evaluate it before slicing.
--
DR.
--
DR.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.