Hi everyone,
I'm looking for the proper django way to do an update of an attribute on my
model instance, but only if the attribute current value is checked agains't
a condition, in an atomic way, something like this:
def use_money(self, value):
begin_transaction()
real_money = F('money')
if real_money >= value:
self.money = F('money') - value
self.save()
end_transaction()
I want to make sure that I avoid race condition so money never goes below 0.
Can you help me out?
Thanks,
Sebastien
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/hr1fBuAcX3kJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.