You need Q objects , and you also need to split the query into separate terms (since no name will match the full string "First Name Last Name").
Here's an idea to match any first or last name starting with "Firstname" or "Lastname" in the search for "Firstname Lastname".
This is a general search - tailor your query to your specific needs!
Edit: oops, I really don't like to use shortening, because it looks confusing, but they must be ORed together, and we cannot do a more detailed version, because the number of terms is unknown.
import operator from django.db.models import Q search_args = [] for term in request.GET['query_term'].split(): for query in ('first_name__istartswith', 'last_name__istartswith'): search_args.append(Q(**{query: term})) all_soggs = Entity.objects.filter(reduce(operator.or_, search_args))
To find out how to use Q objects, when searching for "First Name Last Name" the previous query is:
Entity.objects.filter( Q(first_name__istartswith="Firstname") | Q(last_name__istartswith="Firstname") | Q(first_name__istartswith="Lastname") | Q(last_name__istartswith="Lastname") )
source share