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

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

  •  
  •   huisezhiyin · 2017-05-01 13:23:53 +08:00 · 2180 次点击
    这是一个创建于 2523 天前的主题,其中的信息可能已经有所发展或是发生改变。
    mongoengine 有没有一个类似 django 内建 orm 里面 models 的 post_save/pre_save 函数一样的 可以在指定 documen save 之前或之后触发一个函数的?
    7 条回复    2017-05-02 11:31:45 +08:00
    huisezhiyin
        1
    huisezhiyin  
    OP
       2017-05-01 13:55:08 +08:00
    请教了一下别人找到了解决方案
    1.可以重写 save 方法
    2.可以使用 mongoengine 的 singal 系统
    111111111111
        2
    111111111111  
       2017-05-01 14:17:42 +08:00
    唔…… django 的 post_save/pre_save 不是信号么
    Kilerd
        3
    Kilerd  
       2017-05-01 18:28:26 +08:00 via iPhone
    他的 signal 十分不好用
    yanzixuan
        4
    yanzixuan  
       2017-05-02 09:48:17 +08:00
    @huisezhiyin mongo 没有触发器,所以你要搞这样的指望不了 mongo 本身了,只能靠代码里搞 /
    huisezhiyin
        5
    huisezhiyin  
    OP
       2017-05-02 11:30:40 +08:00
    @111111111111 使用了 mongoengine 操作 mongo 并不是使用 django 的 orm
    huisezhiyin
        6
    huisezhiyin  
    OP
       2017-05-02 11:31:19 +08:00
    @yanzixuan mongoengine 有一个类装饰器拥有和 django 的 post_save/pre_save 一样的功能
    huisezhiyin
        7
    huisezhiyin  
    OP
       2017-05-02 11:31:45 +08:00
    @Kilerd 有比没有好 如果真的不好用的话 考虑重写 save 方法 在 super() save 之前发送一个信号
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1006 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 365ms · UTC 22:01 · PVG 06:01 · LAX 15:01 · JFK 18:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.