Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ndb.transactional(xg=True)
- def transfer_payments(key1, key2, amount):
- [p1, p2] = ndb.get_multi([key1, key2])
- p1.payments += amount
- p2.payments -= amount
- ndb.put_multi([p1, p2])
- class Person(ndb.Model)
- payments = ndb.IntegerProperty(default=0)
- foo = ndb.BooleanProperty()
- def receive_payment(self, other, amount):
- transfer_payments(self.key, other.key, amount) # this is a transaction
- # self now has old data
- self.foo = True
- self.put()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement