Saturday, August 17, 2013

Combine __in and contains query filter to make a more complex filter in django

Combine __in and contains query filter to make a more complex filter in
django

So here's my question :
Say i have a list of some people's full names and I want to filter my
users to check which one of those people are already of my users.
The problem is that users have first name and last name but what I have is
the list of full names, meaning 'first_name+last_name'.
I was trying to filter in 3 steps, first filter all users whose
first_names where in the list and then filter with their last_name.The
third step would be to check for exact matches between the results, But
the problem is I can't filter my users with their first_name in the list
because __in operator looks for exact matches not partial matches.
So:
Is there anyway to do a filter like this :
users.filter(first_name__in__icontains=list_of_people)
or even better, can i have a filter like :
users.filter((first_name+ ' ' + last_name)__in=list_of_people)
?
Any help would be appreciated :)
Thanks

No comments:

Post a Comment