python - How to check if a string contains any one of the value of a list in a query in Django ORM -


i need create query in want check if field "answer_string" contains 1 of value list.

i did in way:

q=queryset.filter(reduce(operator.and_, (q(answer_string__contains = item) item in answerlist))) 

there no. of checkboxes user can select multiple answers , have created list.any value in answer_string field can contain multiple answers in string. want check if string contains 1 of value list should take yes.

this query wrote returns me 0 results. please?

if want check if field contains "any" value of list use operator.or_

operator.and_ concatenates smaller q objects and. current query searching field value contains list values.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -