[Fixed]-Django related_name doesn't work


You have misunderstood how related_name works.

Person.objects.filter() will always return people, not names.

If you want a queryset of names, then do


That will return names linked to the person with id 2 (you don’t need __id because id is the primary key.

The reason that your code is working for husbands/wives is that the field links to the same model.

Leave a comment