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:

  1. is correct, i.e. preserve data integrity?
  2. 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?
  3. if there no way @ database level, tie django catch or ways add new objects db?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -