How can I query on the full name in Django?
To clarify, I essentially want to do create a temporary column, combining first_name and last_name to give a fullname, then do a LIKE on that, like so:
select [fields] from Users where CONCAT(first_name, ' ', last_name) LIKE '%John Smith%";
The above query would return all users named John Smith. If possible I'd like to avoid using a raw SQL call.
The model I'm talking about specifically is the stock django.contrib.auth.models User model. Making changes to the model directly isn't a problem.
For example, if a user was to search for 'John Paul Smith', it should match users with a first name of 'John Paul' and last name 'Smith', as well as users with first name 'John' and last name 'Paul Smith'.
CONCAT(first_name, ' ', last_name)
in SQL) you're going to have to add it to the model. Therefore, include the model in your question.CONCAT(first_name, ' ', last_name) LIKE '%John Smith%"
is terribly inefficient? Usingfirst_name LIKE '%John' AND last_name LIKE 'Smith%'
can be more efficient? Why do you use the CONCAT when there are non-CONCAT ways to do this?