So the background detail, Post is a model, and I am basically trying to create a blog, the same blog as the one shown in this video.
Here is the code:
from django.views.generic import ListView, DetailView
from models import Post
class PublishedPostsMixin(object):
def get_queryset(self):
queryset = super(PublishedPostsMixin, self).get_queryset()
return queryset.filter(published=True)
class PostListView(PublishedPostsMixin, ListView):
# PostListView takes default template name as `post_list.html`,
# as list was the name it was assigned.
model = Post
template_name = 'blog/post_list.html'
class PostDetailView(PublishedPostsMixin, DetailView):
model = Post
template_name = 'blog/post_detail.html'
So, if you can see, PublishedPostsMixin
is inheriting from object, so how is it that the super()
is working. If you can understand what is going on, could you please explain step by step, I'm a little confused.