更新时间:2023-11-21 09:46:28
并非如此.这些信号与 db 事务的成功或失败无关,而是与 save 方法本身有关 - 在调用之前你有 pre_save 信号被触发,在调用之后你有 post_save 信号被触发.
Not really. The signals have nothing to do with the db transaction success or failure, but with the save method itself - before the call you have the pre_save signal fired and after the call you have the post_save signal fired.
这里有两种方法:
instance.saved_successfully = True
,你将在 post_save 处理程序中测试.instance.saved_successfully = True
, which you will test in the post_save handler.有意义吗?
附言
如果您确实需要绑定到事务提交信号,请查看此包:https://django-transaction-hooks.readthedocs.org/en/latest/;看起来该功能已集成在 Django 1.9a 中.
If you strictly need to bind to the transaction commit signal, have a look over this package: https://django-transaction-hooks.readthedocs.org/en/latest/; it looks like the functionality is integrated in Django 1.9a.