A simple solution would be to add another complete_name field in your model. In save you update this field by concatenating the first_name and last_name fields without a space (you need to remove all spaces from the result of the concatenation). Then you will make a request in this field using search_term , but with spaces also separate.
A simple example to give you a general idea:
class Person(models.Model): first_name = CharField(...) last_name = CharField(...) complete_name = CharField(...) def save(self, *args, **kwargs): complete_name = '%s%s' % (self.first_name, self.last_name) self.complete_name = complete_name.replace(' ', '') super(Person, self).save(*args, **kwargs) results = Person.objects.filter(complete_name__icontains=search_term.replace(' ', ''))
source share