Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. @ndb.transactional(xg=True)
  2. def transfer_payments(key1, key2, amount):
  3. [p1, p2] = ndb.get_multi([key1, key2])
  4. p1.payments += amount
  5. p2.payments -= amount
  6. ndb.put_multi([p1, p2])
  7.  
  8. class Person(ndb.Model)
  9. payments = ndb.IntegerProperty(default=0)
  10. foo = ndb.BooleanProperty()
  11.  
  12. def receive_payment(self, other, amount):
  13. transfer_payments(self.key, other.key, amount) # this is a transaction
  14. # self now has old data
  15. self.foo = True
  16. self.put()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement