简体   繁体   English

什么时候在 Django 中执行 post_save() 信号?

[英]When are post_save() signals executed in Django?

I want to override a save() method that is connected to a post_save() signal, if I do, when will the signal be executed?我想重写一个连接到 post_save() 信号的 save() 方法,如果我这样做,信号何时执行? When the method ended or when I call super?当方法结束或当我调用超级时? Here I explain my question with code:在这里,我用代码解释我的问题:

def __init__(self, *args, **kwargs):
    super(Model, self).__init__(*args, **kwargs)
    self.__original_field = self.field

def save(self, force_insert=False, force_update=False, *args, **kwargs):

    if self.__original_field < self.field:
        # Do something
    
    # The signal will be executed after this line?
    super(Model, self).save(force_insert, force_update, *args, **kwargs)

    # Or after this line?        
    self.__original_field = self.field

I used the debugger to solve this doubt and in turns out the signal executes after the super() and then the rest of the save() method is executed.我使用调试器解决了这个疑问,结果信号在 super() 之后执行,然后执行 save() 方法的 rest。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM