简体   繁体   English

如何在现有的peewee查询中添加新的“ .where()”?

[英]How to add a new “.where()” into existing peewee query?

I'm trying to add a new .where to an existing peewee query and I can't. 我试图将一个新的.where添加到现有的peewee查询中,但我做不到。 Using a debugger I see that SQL is not changed after I create the query. 使用调试器,我发现创建查询后SQL不会更改。

My code: 我的代码:

 query = Model.select() \\ .where(Model.year << args.years) if args.models: query.where(Model.title << args.models) if args.company: query.where(Model.company << args.company) else: query.where(Model.company.is_null(True)) if args.make: query.where(Model.make << args.make) 

Peewee doesn't mutate in place, so you simply need to capture the return value of subsequent calls: Peewee不会在适当位置发生突变,因此您只需要捕获后续调用的返回值即可:

if args.models:
  query = query.where(Model.title << args.models)  # Note the query = 

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

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