Answer the question
In order to leave comments, you need to log in
How to output many to many fields in django template?
From the Django documentation
from django.db import models
class Topping(models.Model):
# ...
pass
class Pizza(models.Model):
# ...
toppings = models.ManyToManyField(Topping)
{% for pizza in pizzas %}
В пиццу {{ pizza.name }} входят топпинги:
{% for topping in pizzas.toppings.all %}
{{ topping.name }}
{% endfor %}
{% endfor %}
Answer the question
In order to leave comments, you need to log in
topping.pizza_set.all() or set your own related_name.
toppings = models.ManyToManyField(Topping, related_name='pizza')
---
topping.pizza.all()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question