10.1 最近的礼物
1.首先编写复杂SQL对应的ORM代码
@classmethod
def recent(cls):
# 链式调用 主体是Query ,遇到all(),first()就会终止生成一条sql
# 建造者模式
# select distinct * from gift group by isbn order by create_time limit 30
recent_gifts = Gift.query\
.filter_by(launched=False)\
.group_by(Gift.isbn)\
.order_by(Gift.create_time)\
.limit(30)\
.distinct().all()
return recent_gifts2.业务的四种编写方案
3.编写视图函数
良好的封装是优秀代码的基础
Last updated
Was this helpful?