我需要以事务方式更新NDB模型的某些属性,并且使更新函数成为类方法似乎是明智的:
class Thing(ndb.Model):
cost=ndb.IntegerProperty()
@classmethod
@ndb.transactional()
def add_cost(cls, thid, amount):
thing=cls.get_by_id(thid)
thing.cost+=amount
return thing
Run Code Online (Sandbox Code Playgroud)
因此使用:
# Add 25 to cost
thing=Thing.add_cost(thing.key.id(), 25)
Run Code Online (Sandbox Code Playgroud)
装饰者出现的顺序是否重要?