Django 信号是否在发送者模型的事务中执行
Is django signals excuted inside transaction of sender models
我有一个名为 branch 的模型,我正在使用保存分支:
with transaction.atomic():
#previous processing
obj.save()
#additional codes
我创建 post_save 信号如下:
@receiver(signals.post_save, sender=Branch)
def update_reporter_header(sender, instance,created, **kwargs):
""" When Add or Edit a Branch The related data to branch must be change
Args:
sender ([Branch]): [the model Who kept under eye when any change]
instance ([Branch]): [description]
created ([boolean]): [return true if instance created else False]
"""
if created:
是否是她要求的交易
for obj in HeaderFooter.bobjects.all().filter(branch_id=instance.id,customize=False,is_appeare=True):
obj.data = getattr(instance,obj.name)
obj.save()
执行后我发现在任何信号装饰器中都不需要事务,当且仅当在保存或删除时使用事务。
我有一个名为 branch 的模型,我正在使用保存分支:
with transaction.atomic():
#previous processing
obj.save()
#additional codes
我创建 post_save 信号如下:
@receiver(signals.post_save, sender=Branch)
def update_reporter_header(sender, instance,created, **kwargs):
""" When Add or Edit a Branch The related data to branch must be change
Args:
sender ([Branch]): [the model Who kept under eye when any change]
instance ([Branch]): [description]
created ([boolean]): [return true if instance created else False]
"""
if created:
是否是她要求的交易
for obj in HeaderFooter.bobjects.all().filter(branch_id=instance.id,customize=False,is_appeare=True):
obj.data = getattr(instance,obj.name)
obj.save()
执行后我发现在任何信号装饰器中都不需要事务,当且仅当在保存或删除时使用事务。