django - Read a list of models and block new creations -


i have order model users can create , modify.

an admin user can list of orders of days , send list.

i before admin sends list, closes orders current day, orders closed until next day.

at moment, not see how avoid race condition: - admin closes orders , gets list - user submits order @ same time , thinks order taken account.

the solution have imagined far is:

  • the admin clicks button submits false order indicates orders closed day
  • when form posted, list of orders retrieved
  • when posting order, first check if false order present. if present, validation fail.

but think race conditions still possible.

is there possibility manage @ database level ? example, when closing commands, add constraint in database on date (date new orders must @ least data of following day) ?

you can use atomic decorator database transaction in order check false order. if add check within atomic decorator check race condition can throw error , reset closing day admin order. https://docs.djangoproject.com/en/1.9/topics/db/transactions/#django.db.transaction.atomic


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -