I have 3 models like this:
class Person(models.Model):
name = models.CharField(max_length=100)
class Place(models.Model):
name = models.CharField(max_length=100)
# ManyToMany Through Table
class PersonPlace(models.Model):
person = models.ForeignKey(Person, on_delete=models.CASCADE)
place = models.ForeignKey(Place, on_delete=models.CASCADE)
PersonPlace
links Person
and Place
in a ManyToMany relationship.
I want a database query that will give me a list of place id
's per person (a list of places every person has visited).
Is it possible to make that aggregation through the ORM without having Python put this together?
Expected return is something like: {1: [4,5,6], 2: [1,2,5]}
The keys here are the user ids, and the values are the place ids each user has visited. Note: The result does NOT need to be a dict, but I would assume it would be something dict-like.