我正在使用带有 Python 和 DataStore 的 Google App Engine。是否可以定义模型并将函数直接附加到模型?
class ServiceState(db.model):
service = db.StringProperty(required=True,
choices=('API', 'DB'))
current = db.StringProperty(required=True,
choices=('UP', 'DOWN'))
def change(self, new_state):
# some other logic here
self.current = new_state;
self.put()
然后执行以下操作:
ss = models.ServiceStatus.gql("WHERE service = :1", "API")
ss.change("DOWN")
更新
尝试并获得:
AttributeError: 'GqlQuery' object has no attribute 'change'