如何更新SQLAlchemy行条目? [英] How to update SQLAlchemy row entry?

查看:61
本文介绍了如何更新SQLAlchemy行条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设表有三列:usernamepasswordno_of_logins.

当用户尝试登录时,将使用查询之类的条目检查该条目

When user tries to login, it's checked for an entry with a query like

user = User.query.filter_by(username=form.username.data).first()

如果密码匹配,他将继续.我想做的是计算用户登录的次数.因此,每当他成功登录时,我都想增加no_of_logins字段并将其存储回用户表.我不确定如何使用SqlAlchemy运行更新查询.

If password matches, he proceeds further. What I would like to do is count how many times the user logged in. Thus whenever he successfully logs in, I would like to increment the no_of_logins field and store it back to the user table. I'm not sure how to run update query with SqlAlchemy.

推荐答案

user.no_of_logins += 1
session.commit()

这篇关于如何更新SQLAlchemy行条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆