V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
caixiexin
V2EX  ›  Python

flask-SQLAlchemy 的 update 操作是怎么用的呢?

  •  
  •   caixiexin · 2016-02-09 13:13:40 +08:00 · 28113 次点击
    这是一个创建于 2997 天前的主题,其中的信息可能已经有所发展或是发生改变。
    求教,为啥我在官网的教程里只发现 insert query 和 delete - -
    http://flask-sqlalchemy.pocoo.org/2.1/queries/
    10 条回复    2016-02-10 01:15:57 +08:00
    chinafeng
        1
    chinafeng  
       2016-02-09 13:20:50 +08:00
    老蔡过年还不忘吸取知识啊
    paicha
        2
    paicha  
       2016-02-09 13:21:00 +08:00   ❤️ 1
    修改对象之后,再次 commit
    caixiexin
        3
    caixiexin  
    OP
       2016-02-09 13:21:32 +08:00
    @chinafeng 别打岔- -||
    caixiexin
        4
    caixiexin  
    OP
       2016-02-09 13:22:58 +08:00
    @paicha 直接把 query 出来的对象修改完,然后 db.session.commit()吗?试了下貌似不起作用呢。。
    paicha
        6
    paicha  
       2016-02-09 13:29:26 +08:00   ❤️ 1
    caixiexin
        7
    caixiexin  
    OP
       2016-02-09 13:34:06 +08:00
    @paicha thanks~
    wellsc
        8
    wellsc  
       2016-02-09 21:39:26 +08:00 via iPhone
    同样也可以使用 Sqlalchemy 的 update 方法。
    honmaple
        9
    honmaple  
       2016-02-10 01:11:47 +08:00 via Android
    一般都是先 query,再 commit ,没有什么问题啊
    honmaple
        10
    honmaple  
       2016-02-10 01:15:57 +08:00 via Android   ❤️ 2
    user = User.query.filter_by(id=post_id).first()
    user.name = xxx
    db.session.commit()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   951 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:25 · PVG 05:25 · LAX 14:25 · JFK 17:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.