I have the following models:
class Person(...):
name = CharField(...)
class Address(...):
person = ForeignKey(Person)
address = CharField(...)
I need to select all persons that have exactly two addresses.
So if my Address table looks like this:
----------------------------
| id | person_id | address |
----------------------------
| 1 | 1 | xyz |
| 2 | 1 | xyz |
| 3 | 2 | xyz |
| 4 | 3 | xyz |
| 5 | 3 | xyz |
| 6 | 4 | xyz |
| 7 | 5 | xyz |
| 8 | 5 | xyz |
| 9 | 5 | xyz |
----------------------------
The resulting queryset should be
<QuerySet [<Person: 1>, <Person: 3>]>
I tried a lot, but just don't seem to get it right. I would be glad for a quick fix.