Reputation: 948
Well I am trying to create a Playlist quite similar with YouTube. But the Playlist can only create by superuser from admin panel and other user can only see that playlist and the videos within the playlist. When I thought that I am done than suddenly this error occured. I don't know where I am making mistake. Please help me to fix this problem.
videos/models.py
class VideosList(models.Model):
list_title = models.CharField(max_length=255)
list_cover = models.ImageField(upload_to='list cover', height_field=None, width_field=None, max_length=None,blank =True)
create_date = models.DateField(default = timezone.now)
def __str__(self):
return self.list_title
class VideosModel(models.Model):
videos_lists = models.ForeignKey(VideosList,on_delete=models.CASCADE)
video_title = models.CharField(max_length=250)
video_url = models.URLField(max_length=1200)
video_discription = models.TextField()
create_date = models.DateField(default = timezone.now)
def __str__(self):
return self.video_title
videos/views.py
class VideosListView(ListView):
model = VideosList
context_object_name = 'videos_lists'
template_name = "videos/videos_lists.html"
def get_queryset(self):
return VideosList.objects.filter(create_date__lte=timezone.now()).order_by('-create_date')
class VideosModelListView(ListView):
model = VideosModel
template_name = "videos/list_videos.html"
context_object_name = 'videos_list'
def get_queryset(self,*args, **kwargs):
videoslist = get_object_or_404(VideosList, list_title=self.kwargs.get('list_title'))
return VideosModel.objects.filter(videos_lists=videoslist).order_by('-create_date')
videos/urls.py
app_name = 'videos'
urlpatterns = [
path('list/',views.VideosListView.as_view(),name ='videos_playlist'),
path('list/<str:list_title>/',views.VideosModelListView.as_view(),name ='list_videos'),
]
videos/videos_list.html
{% extends 'pages/videos.html' %}
{% block content %}
{% for all_lists in videos_lists %}
<p style='text-align:center'><img src="{{ all_lists.list_cover.url }}" alt="No cover" height="450px" width="550px" ></p>
#This h2 line generating error and I dont know how to fix it.
<h2 style='text-align:center'>Title :<a href="{% url 'list_videos' all_lists.videos_lists.list_title %}"> {{ all_lists.list_title }}</a></h2>
<div class="date">
<p style='text-align:center'>
Published on: {{ all_lists.create_date|date:"D M Y" }}
</p>
</div>
<br></br>
{% endfor %}
{% endblock content %}
videos/list_videos.html
{% extends 'pages/videos.html' %}
{% block content %}
<h1 style='text-align:center'>List : {{ view.kwargs.list_title }}</h1>
{% for all_videos in videos_list %}
<h2 style='text-align:center'>{{ all_videos.videos_lists }}</h2>
<p style ='text-align:center'>
<object style="height: 390px; width: 640px"><param name="movie" value=""><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="{{all_videos.video_url}}" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></object>
</p>
<p style ='text-align:center'>
Discription :{{all_videos.discription}}
</p>
<div class="date">
<p style='text-align:center'>
Published on: {{ all_videos.create_date|date:"D M Y" }}
</p>
</div>
<br></br>
{% endfor %}
{% endblock content %}
Upvotes: 0
Views: 88
Reputation: 878
In your videos/videos_list.html update <a>
tag like this,
<a href="{% url 'videos:list_videos' all_lists.videos_lists.list_title %}"> {{ all_lists.list_title }}</a>
Upvotes: 1