flask 数据库进阶(flask 30)

2019-08-13 14:41:53 浏览数 (1)

级联: class Witer(db.Model): books=db.relationship('writer',cascade='save-update,merge,delete')

save-update,merge

all all,delete-orphan

尽量不要设置 delete-orphan

事件监听: set append remove init_scalar init_collection

当字段被重新编辑时,记录被编辑的次数

设置

@db.event.listens_for(Post.body,'set') def increment_edit_time(target,value,oldvalue,initiator): if target.edit_time is not None: target.edit_time =1

or 字典方式:

image.png

0 人点赞