django/django — pull request #1519 by iorlas (2013-08-27 10:05:19+00:00)
Title: Fixed bug #2818 with another side of ForeignKey. Missed condition detail in a89b156 commit

As we can see, in https://code.djangoproject.com/ticket/2818 we have fixed bug in django admin behavior with joins - we should use distinct in this cases. Commit 4938c8e fixed this issue.
But, in a89b156 it was reworked as set of codelines for enhanced conditions. To check for possible joins, was created function lookup_needs_distinct. It looks for field by name(for example, in 'user__docs__name' it takes 'user') and does some checks to verify is it relation object.
As we can see, RelatedObject(any relation) and ManyToManyRel(reverse side of ManyToMany) handled. But, we also have reverse side of ForeignKey - ManyToOneRel. So yea, we have a problem here - appearance of bug #2818. So I decide to create this pull request. At least, it works perfectly for me.
FYI, I'm not checking for OneToOneRel, because there should be no duplications in this case.