V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
Melodic
V2EX  ›  Python

Django 中关于原子性,使用@transaction.atomic 还是@transaction.commit_on_success?

  •  
  •   Melodic · Sep 24, 2014 · 5636 views
    This topic created in 4240 days ago, the information mentioned may be changed or developed.
    有没有人解释一下,貌似atomic适用的范围更广一些,但是极大的影响效率。
    3 replies    2015-09-16 11:16:38 +08:00
    yueyoum
        1
    yueyoum  
       Sep 24, 2014   ❤️ 1
    应该用 transaction.atomic

    https://docs.djangoproject.com/en/dev/topics/db/transactions/

    commit_on_success 是旧API,在django1.8以后会移除

    并且, commit_on_success 从文档来看 只能用作装饰器

    但atomic 除了装饰器,还可以用于 with 语法

    with transaction.atomic():
    ....xxx
    Melodic
        2
    Melodic  
    OP
       Sep 25, 2014
    @yueyoum 谢谢。话说1.8好遥远啊
    ziming2018
        3
    ziming2018  
       Sep 16, 2015
    @Melodic 不遥远,早就出来了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   860 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 19:06 · PVG 03:06 · LAX 12:06 · JFK 15:06
    ♥ Do have faith in what you're doing.