For example I have two model objects, Person and Address. Address has a reference to a Person id. What would a query look like that pulls them out together as one object, or is that not possible to do with Django?
For example I have two model objects, Person and Address. Address has a reference
Share
Have a read of the Django docs on related objects. Going from a Person to related Addresses is equivalent to going from a Blog to its related Entries in the examples.
If you have a person, you can do
person.address_set.all()to get all addresses for that person.If each person has only one address, use a
OneToOneField, and then you can useperson.addressto get the address.