I have the following db classes:
class Account(db.Entity):
id = PrimaryKey(int, auto=True)
name = Required(str)
balance = Required(Decimal, precision=2, default=0)
transactions = Set('Transaction')
class Transaction(db.Entity):
id = PrimaryKey(int, auto=True)
datetime = Required(datetime, precision=0, default=lambda: datetime.now())
account = Required(Account)
value = Required(Decimal, precision=2)
description = Optional(str)
def after_insert(self):
self.account.balance += self.value
def before_delete(self):
self.account.balance -= self.value
def before_update(self):
pass
I did not find a way to reduce the balance like:
def before_update(self):
self.account.balance += self.value - self.value.old_value
Is there any way to get the old attribute value?
I found a loophole: