我正在尝试显示用户保存为播放列表一部分的每个视频的视频网址。用户还可以保存多个播放列表(视图中的第一行显示所有播放列表)。不过,我正在努力弄清楚如何在每个播放列表中显示视频。有什么建议吗?
视图.py
def profile(request):
playlist = UserPlaylist.objects.filter(profile=request.user)
return render_to_response('reserve/templates/profiles.html', {'playlist':playlist},
context_instance=RequestContext(request))
模型.py
class Playlist(models.Model):
playlist = models.CharField('Playlist', max_length = 2000, null=True, blank=True)
def __unicode__(self):
return self.playlist
class Video(models.Model):
video_url = models.URLField('Link to video', max_length = 200, null=True, blank=True)
def __unicode__(self):
return self.video_url
class UserPlaylist(models.Model):
profile = models.ForeignKey(User)
playlist = models.ForeignKey(Playlist)
def __unicode__(self):
return unicode(self.playlist)
class Videoplaylist(models.Model):
video = models.ForeignKey(Video)
playlist = models.ForeignKey(UserPlaylist)
def __unicode__(self):
return unicode(self.playlist)
模板:profiles.html
{% for feed in playlist %}
{{feed}}
<br>
{% endfor %}