[Answer]-How to use foreign key to get related objects?

1👍

person.image_set.all() is one way, and if needed you can also filter through the images of a person for a given query, e.g. persom.image_set.filter(...), and if you just want the count, person.image_set.count()

You can read more on how to query for related objects here: https://docs.djangoproject.com/en/1.8/topics/db/queries/#related-objects

👤bakkal

Leave a comment