1
knightdf 2020-01-07 13:17:10 +08:00
```python
filters = [] if xxx is not None: filters.append(Model.attr == xxx) .query.filter(*filters).xxxx ``` |
2
hp66722667 2020-01-07 16:55:25 +08:00
通过 if 判断一下字段,不就可以随便拼接 sql 语句了么
|
3
6167 2020-01-07 17:00:52 +08:00
```
if not xxx: data = Xxx.query.all() ``` |
4
SjwNo1 2020-01-07 17:04:26 +08:00
你都用 SQLAlchemy 了~~
''' if cond is None: objs = Xxx.query.all() ''' |
5
l4ever 2022-03-25 08:39:28 +08:00
```
filters = [OrderModel.date == date] if isinstance(date, str) else [OrderModel.date.in_(date)] filters += [OrderModel.type.in_(type)] if type else [] filters += [OrderModel.successed == successed] if successed else [] order_list = OrderModel.query.filter(*filters).all() order_name = [f.name for f in order_list] return list(set(order_name)) ``` |