Thomas Steinacher wrote: > I know that in this specific case it can be enforced at database level > using the unique and unique_together properties, but how would you > handle e.g. this scenario? > > 1 def transfer_money(from_id, to_id, amount) > 2 from = models.BankAccount.objects.get(id=from_id) > 3 to = models.BankAccount.objects.get(id=to_id) > 4 from.balance -= amount > 5 to.balance += amount > 6 from.save() > 7 to.save() > > What, if two Django processes transfer money from account A to account > B simultaneously? >
these situations are (afaik) handled using transactions....simply start a transaction at the beginning, and commit/rollback at the end... gabor --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---