Reputation: 1688
I am little new to Django,
My Question is How do i do %LIKE% of MYSQL in Django Filter
Want something like this
myModel.objects.filter(myField__**like**="xyz")
as we can do
myModel.objects.filter(myField__startswith="xyz")
for strings that starts with 'xyz' but i want to match anywhere in the myField content.
What i know it can be done by REGEX and .extra() but i want something very straight forward.
Thanks in advance.
Upvotes: 0
Views: 1214
Reputation: 192
You can do it like this:
myModel.objects.filter(myField__contains = "xyz")
Note: __contains is case sensitive. You can use __icontains
if you don't care about the case of the text.
Upvotes: 4
Reputation: 55448
Use the contains
operator my_model.objects.filter(my_field__contains='xyz')
and icontains
if you want case insensitivity
Upvotes: 2