[Fixed]-Django related_name doesn't work

1👍

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

Name.objects.filter(person=2)

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