Answer the question
In order to leave comments, you need to log in
How to properly group a queryset?
Hello!
Let's take for example:
class Car(models.Model):
manufacturer = models.ForeignKey('Manufacturer')
# ...
class Manufacturer(models.Model):
# ...
pass
{% for manufacturer, cars in car_list %}
<h1>{{ manufacturer.name }}</h1>
{% for car in cars %}
<p>{{ car.name }}</p>
{% endfor %}
{% endfor %}
Answer the question
In order to leave comments, you need to log in
related_name
{% for man in m %}
<h1>{{ man.name }}</h1>
{% for car in man.cars.all %}
<p>{{ car.name }}</p>
{% endfor %}
{% endfor %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question