For example, I have these models:
class Person(models.Model):
name = models.CharField(max_length=20)
employer = models.CharField(max_length=20)
class Car(models.Model):
person = models.ForeignKey(Person)
name = models.CharField(max_length=10)
model = models.CharField(max_length=10)
...
I want to get all people who own some specific car:
people = Person.objects.filter(car__name="Toyota")
Now I want to write these people out with details about their own car. I can do this:
for person in people:
...
cars = person.car_set.filter(name="Toyota")
...
But it hit the database again. How can I avoid this? Is there any way to do this simpler?