Select_related () feedback - car model population

If I have the following model:

class Contact(models.Model)
    name = models.CharField(max_length=100)
    ...

class ContactAddress(models.Model)
    line1 = models.CharField(max_length=100)
    line2 = models.CharField(max_length=100)
    ...
    contact = models.ForeignKey(Contact)

Now I want to capture all the contacts and the address, which will be automatically filled. What would be the best way to do this? The only way I've found so far is to filter out the contacts that I want, and go around each contact and assign it to a contact. Then I use this to display each contact address in the template.

Is there a better way to do this? Select_related () almost does what I want, but doesn't seem to be able to work in the opposite direction.

Thanks in advance for your help!

+5
source share
1 answer

, select_related ! , . this!

+4

All Articles