是的,为自动提交的连接设置(由transaction.commit装饰器调整)以相同的值调度信号,该值用于保存模型。在django.db.models.base.Model.save_base()方法中引用代码,
if not meta.auto_created: signals.pre_save.send(sender=origin, instance=self, raw=raw, using=using, update_fields=update_fields) with transaction.atomic(using=using, savepoint=False): if not raw: self._save_parents(cls, using, update_fields) updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) # Store the database on which the object was saved self._state.db = using # once saved, this is no longer a to-be-added instance. self._state.adding = False # Signal that the save is complete if not meta.auto_created: signals.post_save.send(sender=origin, instance=self, created=(not updated),update_fields=update_fields, raw=raw, using=using)
如您所见,没有编写任何特殊代码来更改自动提交设置。因此,如果您的视图声明所有与数据库有关的东西都必须使用@
transaction.atomic来确保原子性,那么直到您的视图通过视图(无论是model.save()还是通过信号处理程序)进行的数据库更改都不会提交执行完成。
希望对您有所帮助。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)