Veme
Veme

Reputation: 215

Django template question?

I need to display all the videos within a certain playlist. I can display all the avaliable playlists by using this loop:

{% for p in playlists %}

    {{ p.playlist.name }}

{% endfor %}

How can I display all the videos in each playlist too?

Upvotes: 0

Views: 55

Answers (1)

Mike DeSimone
Mike DeSimone

Reputation: 42805

It's hard to say since you don't show your models, but something like this could work:

<ul>
{% for p in playlists %}

<li>{{ p.playlist.name }}
    <ul>
    {% for v in p.playlist.videos %}
    <li>{{ v.name }}</li>
    {% endfor %}
    </ul>
</li>
{% endfor %}
</ul>

I'm assuming your videos have a ForeignKey(Playlist, related_name="videos") field.

Upvotes: 1

Related Questions