Skip to content
Advertisement

How to Query model where name contains any word in python list?

Aim to Achieve:

I want all objects where name attribute contains any word from the list.

I have:

JavaScript

For example:

if name="this is word2": Then object with such a name should be returned since word2 is in the list.

Please help!

Advertisement

Answer

You could use Q objects to constuct a query like this:

JavaScript

Edit:

JavaScript

is a fancy way to write

JavaScript

You could also use an explicit for loop to construct the Q object.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement