Post and comment models
class Post(models.Model):
title = models.CharField(max_length=120)
content = models.TextField()
class Comment(models.Model):
post = models.ForeignKey(Post, on_delete=models.CASCADE)
content = models.TextField()
Class view of post detail
class PostDetailView(DetailView):
model = Post
context_object_name = 'post'
template_name = 'posts/detail.html'
def get_queryset(self, *args, **kwargs):
request = self.request
pk = self.kwargs.get('pk')
queryset = Post.objects.filter(pk=pk)
return queryset
In the template I do something like this
{% for comment in post.comment_set.all %}
{% comment.content %}
{% endfor %}
In this approach, all the comments are shown in the post detail page. However, I want to paginate the comments of a post so that I can do pagination on comments and not show the whole list of comments.
How can I do this?