I have a model I want to filter with a search term, which is usually a name. However in my database first_name and last_name are two separate fields.
e.g.
search_term = 'Will Sm'
db_persons record: first_name = 'Will', last_name = 'Smith'
the search term would be able to retrieve this record.
How can I achieve that?
db_persons.objects.filter(__?__)
UPDATE:
Looking for a way to concatenate fields and querying the concatenated result without raw sql
A simple solution will be to add another field
complete_nameon your model. Onsaveyou will update this field by concatenatefirst_nameandlast_namefields without any space (you need to strip all spaces from the concatenation result). Then you will do your query on this field with thesearch_termbut with spaces also stripped.Simple example to give you the general idea: