Where do I put methods that perform create_if_missing or update_if_exists function in django?
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.
精彩评论