[英]django commit_on_success usage
我有一系列方法可用于另一个方法调用,即Django中的管理/命令句柄。 如何确保序列中所有方法的完成。 所有这些方法不一定都返回值。 我可以使用commit_on_success作为句柄吗? 还有其他更好的方法吗? 基本上,某些方法会更新postgresql表中的一些重要值,并根据这些值为下一个方法调用做出某些决策。 请还原。我在Linux上使用Django 1.6.5
我遇到了类似的问题,并且正在使用transaction.commit_manually
。 我的代码如下所示:
# Some actions before
with transaction.commit_manually():
try:
# Some actions that will be saved in DB
except:
# Log error message
transaction.rollback() # Rollback if there was an error during the execution
return error_response # Stop execution of the method and return the response
transaction.commit() # If return was not initiated before, it means that there were no errors, so we can do commit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.