Reputation: 617
Table definition:
class Hello(models.Model):
name models.CharField(max_length=64, blank=True)
2 records are in db:
#1 aaaa-bbbb (cd)
#2 aaa-bbbb (cef)
The search key word: 'aaa-bbbb', or 'aaa-bbbb (c',
ret = models.Hello.objects.filter(Q(name__icontains='aaa-bbbb'))
Expected result is #2, but 2 records are found.
How to find #2?
Upvotes: 0
Views: 1437
Reputation: 107
Instead of icontains
use iexact
like this:
ret = models.Hello.objects.filter(name__iexact='aaa-bbbb')
You don't need to use Q
if you are filtering through only one field
Upvotes: 1