知识点 一、模型数据更新 二、模型数据删除python
咱们前两章实现了对模型类的添加和查询,在开发过程当中,查询是比较重要的一个环节。接下来咱们要学习的就是对模型的更新和删除。session
hero = Hero.query.get(1)
hero.name = '伽罗'
db.session.add(hero)
db.session.commit()
复制代码
咱们在本地查询一下: 学习
Hero.query.filter_by(id=1).update({"name":"虞姬","gender":"女"})
db.session.commit()
复制代码
咱们在本地查询一下:spa
hero = Hero.query.get(4)
db.session.delete(hero)
db.session.commit()
复制代码
咱们在本地查询一下: code
欢迎关注个人公众号:cdn