I have this model on Django:
class Profile(models.Model):
name = models.CharField(max_length=50, blank = False)
surname = models.CharField(max_length=100, blank = False)
...
For example, I have 2 profiles in the db:
- John Doe
- John Smith
I want to do a form search, that searches in both name and surname attributes.
I tried:
Q(name__icontains=text) | Q(surname__icontains=text)
But this doesn't work, for example if I search "John Doe" it returns both of them.
Edit: Basically what I want is something like "joining" both name and surname attributes to search in, so when I search "John" it shows me "John Doe" and "John Smith", and when i search "John Doe" it shows me only the "John Doe" profile.