sql “LIKE” equivalent in django query

example:
 
result = table.objects.filter(string__contains='pattern')
 
 
 

icontains

Case-insensitive containment test.
Example:
Entry.objects.get(headline__icontains='Lennon')
SQL equivalent:
SELECT ... WHERE headline ILIKE '%Lennon%';
 
 
====
 
 

contains

Case-sensitive containment test.
Example:
Entry.objects.get(headline__contains='Lennon')
SQL equivalent:
SELECT ... WHERE headline LIKE '%Lennon%';
Note this will match the headline 'Lennon honored today' but not 'lennon honored today'.
 

No comments:

Post a Comment