python - Django: Validating data with protection against race conditions -
i writing django application booking resources. reservation model more complicated, think of hotel room have check-in , check-out date. clearly, each new reservation needs checked against conflicting data in db , there might race condition, if 2 conflicting reservations entered simultaneously. did:
# q: unevaluated queryset pulls conflicting reservations db # r: new reservation object transaction.atomic(): if not q.exists(): # no conflicts, if empty r.save()
my questions:
- is correct, i.e. preserve data integrity?
- is there native django way (no raw sql) insert integrity check right database? assume best way in order prevent possible way of invalid data entering db?
- if there no way @ database level, tie django catch or ways add new objects db?
Comments
Post a Comment