I have a seach by name function, which should return the name of one person, if the search matches the first name or the last name. The problem is that if i search for strings like 'firstname lastname' it doesn't find the name that matches (guess it's because of the space between the words) . What should i do for the search to work? Also, if i want to search with the same search the username (wich is in another table) how can i do it? Thanks a lot!
my code:
def search(request):
query = request.GET.get('q', '')
if query:
qset1 = (
Q(first_name__icontains=query) |
Q(last_name__icontains=query)
)
results = UserProfile.objects.filter(qset1).distinct()
else:
results = []
return render_to_response("search/searchName.html", {
'results': results,
'query': query},
context_instance=RequestContext(request))