Django Select_related In Template
Sometimes it makes sense to use select_related in a django template. For example, say I have a class extending DetailView class DemoCarView(DetailView): model = Car Based on t
Solution 1:
How about a simple method on the Car
model?
classCar(models.Model):
...
defparts_with_manufacturers(self):
returnself.part_set.select_related('manufacturer')
and then
{% for part in car.parts_with_manufacturers %}
<li>{{ part.name }} - {{ part.manufacturer.name }} </li>
{% endfor %}
Post a Comment for "Django Select_related In Template"