views.py
paginate_by is not working, is there any alternative for this.
class PostListView(ListView):
template_name = 'all_users/doctor/main.html'
model = Post
context_object_name = 'posts'
paginate_by = 3
def get(self, request, **kwargs):
query = self.request.user
post = Post.objects.filter(author=User.objects.get(username=query)).order_by('-date_posted')
context = {
'posts': post,
}
return render(request, self.template_name, context)
Django will paginate the queryset that originates from the
get_queryset
. So you can implement the view with:It will add the
Page
object to the context with the namepage_obj
. So you can iterate over it with: