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?
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.
精彩评论