Skip to content

Latest commit

 

History

History
41 lines (24 loc) · 914 Bytes

README.md

File metadata and controls

41 lines (24 loc) · 914 Bytes

flask-softdeletes

介绍

flask-softdeletes 基于flask-sqlalchemy的软删除实现

使用简介

1.安装

pip install flask-softdeletes

2.导入 SoftDeletedMixin

from flask_softdeletes import SoftDeletedMixin

3.模型类继承 SoftDeletedMixin

class DemoModel(SoftDeletedMixin, db.Model):pass

4.使用查询

[查询正常的数据,不包含已被软删除数据]
DemoModel.query

[只查询已经被软删除的数据]
DemoModel.query.only_trashed

[查询所有的数据, 包括已被软删除的和没有被软删除的数据]
DemoModel.query.with_trashed

[软删除数据]

demo = DemoModel.query.get(1)

demo.delete()

[恢复软删除的数据]

demo = DemoModel.query.with_trashed.get(1)

demo.restore()