Razindra firman
Razindra firman

Reputation: 11

object filtering in template django

I have 2 class of model post and comment for loops in my template like this

I have a for loop like this

{% for post in posts %}

{% endfor %}

and I want to make filter like this Comment.objects.filter(post=post.id) in my for loop and get some value

how to write it properly?

Upvotes: 0

Views: 203

Answers (1)

sandeshdaundkar
sandeshdaundkar

Reputation: 903

{% for post in posts %}
    {% for comment in post.comments.all %}
        {{ comment }}
    {% endfor %}
{% endfor %}

Upvotes: 2

Related Questions