Skip to content

Commit

Permalink
search for last name too if term has a space in it
Browse files Browse the repository at this point in the history
  • Loading branch information
jsayles committed Dec 7, 2016
1 parent dc14292 commit 73ff49e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions members/views/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ def user_search(request):
term = request.GET.get('term', '').strip()
query = User.objects.all()
if len(term) >= 3:
first = Q(first_name__icontains=term)
last = Q(last_name__icontains=term)
query = query.filter(first | last)
if ' ' in term:
terms = term.split(' ')
first = Q(first_name__icontains=terms[0])
last = Q(last_name__icontains=terms[1])
query = query.filter(first & last)
else:
first = Q(first_name__icontains=term)
last = Q(last_name__icontains=term)
query = query.filter(first | last)
elif len(term) > 0:
query = query.filter(first_name__istartswith=term)
items = []
Expand Down

0 comments on commit 73ff49e

Please sign in to comment.