开发者

Where do I put methods that perform create_if_missing or update_if_exists function in django?

开发者 https://www.devze.com 2023-03-18 14:59 出处:网络
In what location should I place methods that perform: Create this row if it is missing Update the row if it exists

In what location should I place methods that perform:

  • Create this row if it is missing
  • Update the row if it exists

for a django model ?

Additionally since I am using the default transaction scheme of django, this migh开发者_JAVA百科t introduce race conditions. How do I prevent that ?


Django has this built-in: get_or_create.


The answer is get_or_create.

I suppose it is obligatory to link to their docs as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消