簡體   English   中英

django commit_on_success用法

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM