Reputation: 45
I'm trying to add a new .where to an existing peewee query and I can't. Using a debugger I see that SQL is not changed after I create the query.
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)
Upvotes: 2
Views: 360
Reputation: 26235
Peewee doesn't mutate in place, so you simply need to capture the return value of subsequent calls:
if args.models:
query = query.where(Model.title << args.models) # Note the query =
Upvotes: 2