[Answered ]-Django selecting distinct field not working

2👍

Your query returns distinct TeamMembernot distinct user.

In order to get distinct user:

user.objects.filter( 
                teammember__team__teammember__user__icontains=query
          ).exclude(user=request.user).distinct()

Explained: distincts users that they teammember has a team that is related to a teammember that has a user that contains query all this excluding logged user.

Leave a comment