0

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.

1

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Use the contains operator my_model.objects.filter(my_field__contains='xyz') and icontains if you want case insensitivity

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.