[Fixed]-I don't have slug as my argument in my function in view(I only have request), how do I get specific post with slug

1👍

The easiest way would be to add a method to count comments to your Post model:

class Post(models.Model):
    ...
    def comments_count(self):
        return Comment.objects.filter(post=self).count()

then use it in your template such as:

{% for post in posts %}
    {{ post.title }}: {{ post.comments_count }}
{% endfor %}
👤Selcuk

Leave a comment