flask-softdeletes 基于flask-sqlalchemy的软删除实现
pip install flask-softdeletes
from flask_softdeletes import SoftDeletedMixin
class DemoModel(SoftDeletedMixin, db.Model):pass
[查询正常的数据,不包含已被软删除数据]
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()