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
huisezhiyin
V2EX  ›  Python

想请教一个有关于 mongoengine 的问题

  •  
  •   huisezhiyin · May 1, 2017 · 2728 views
    This topic created in 3284 days ago, the information mentioned may be changed or developed.
    mongoengine 有没有一个类似 django 内建 orm 里面 models 的 post_save/pre_save 函数一样的 可以在指定 documen save 之前或之后触发一个函数的?
    7 replies    2017-05-02 11:31:45 +08:00
    huisezhiyin
        1
    huisezhiyin  
    OP
       May 1, 2017
    请教了一下别人找到了解决方案
    1.可以重写 save 方法
    2.可以使用 mongoengine 的 singal 系统
    111111111111
        2
    111111111111  
       May 1, 2017
    唔…… django 的 post_save/pre_save 不是信号么
    Kilerd
        3
    Kilerd  
       May 1, 2017 via iPhone
    他的 signal 十分不好用
    yanzixuan
        4
    yanzixuan  
       May 2, 2017
    @huisezhiyin mongo 没有触发器,所以你要搞这样的指望不了 mongo 本身了,只能靠代码里搞 /
    huisezhiyin
        5
    huisezhiyin  
    OP
       May 2, 2017
    @111111111111 使用了 mongoengine 操作 mongo 并不是使用 django 的 orm
    huisezhiyin
        6
    huisezhiyin  
    OP
       May 2, 2017
    @yanzixuan mongoengine 有一个类装饰器拥有和 django 的 post_save/pre_save 一样的功能
    huisezhiyin
        7
    huisezhiyin  
    OP
       May 2, 2017
    @Kilerd 有比没有好 如果真的不好用的话 考虑重写 save 方法 在 super() save 之前发送一个信号
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3574 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 04:47 · PVG 12:47 · LAX 21:47 · JFK 00:47
    ♥ Do have faith in what you're doing.