Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do query with `WHERE value IN list` in the Python Peewee ORM?

I'm using the (awesome) Python Peewee ORM for my Flask project, but I now got stuck trying to do a query with a where value in ['a', 'b', 'c']. I tried doing it as follows:

MyModel.select().where(MyModel.sell_currency in ['BTC', 'LTC'])

But unfortunately it returns all records in the DB. Any ideas how I could do this?

like image 557
kramer65 Avatar asked Aug 07 '14 09:08

kramer65


1 Answers

The docs has the answer: x << y will perform x IN y, where y is a list or query. So the final query will look like:

MyModel.select().where(MyModel.sell_currency << ['BTC', 'LTC'])

like image 56
ambi Avatar answered Oct 15 '22 03:10

ambi