SQLALCHEMY or_ list comprehension
<p>I'm trying to use list comprehension with or_. I already found a post that showed how to do it with only checking one column, but I'm unsure how to check two columns simultaneously with a list. I tried something like this:</p>

<p><code>q = q.filter(or_((model.column.contains(word), model.column2.contains(word))for word in search))</code></p>

<p>This gives me a bad request though. Any advice on how to search simultaneously  using a list would be appreciated!</p>

<p>From what I understand you need to <em>unpack</em> the conditions into positional arguments of <a href="http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.expression.or_" rel="nofollow"><code>or_()</code></a>:</p>

<pre><code>columns = [model.column, model.column2]
conditions = [column.contains(word) for word in search for column in columns]
q = q.filter(or_(*conditions))
</code></pre>

<p>Assuming you want to "or" every contains for every word and for all given columns.</p>

python sqlalchemy flask-sqlalchemy