简体   繁体   English

Peewee - 查询['str'in item]

[英]Peewee - query ['str' in item]

I know I'm doing this the wrong way - how do I do this without a list comprehension but with a query in peewee. 我知道我这样做的方式是错误的 - 如何在没有列表理解但是在peewee中查询的情况下这样做。 I would like to get a query to see if a search term is "in" the objects parameter. 我想查询一个搜索词是否在“对象”参数中。

knights = Knight.select()
knights = [knight for knights in knights if request.args.get('ni').lower() in \
knights.who_say.lower() ]

Look at http://peewee.readthedocs.org/en/latest/peewee/querying.html#column-lookups 请看http://peewee.readthedocs.org/en/latest/peewee/querying.html#column-lookups

A real example might be better I'm not clear what you're trying to do exactly....but it looks like you want the case insensitive 'like'. 一个真实的例子可能会更好我不清楚你正在尝试做什么......但看起来你想要不区分大小写'喜欢'。

ni = request.args.get('ni')
Knights.select().where(Knights.who_say ** ni.join(('%', '%')))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM