[Django]-Retrieve info from many-to-many relationship in django temaplate

4👍

You can access the categories with this

{% for category in post.categories.all %}
    {{ category.title }}
{% endfor %}

I also recommend adding .prefetch_related('categories') to the queryset in your view to reduce the number of sql queries.

Leave a comment