1

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 might introduce race conditions. How do I prevent that ?

Frankie Ribery
  • 11,933
  • 14
  • 50
  • 64

2 Answers2

1

Django has this built-in: get_or_create.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
1

The answer is get_or_create.

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

Community
  • 1
  • 1
cwallenpoole
  • 79,954
  • 26
  • 128
  • 166