在Google App Engine DataStore中为模型添加功能

时间:2013-08-15 21:03:25

标签: python google-app-engine model

我正在使用带有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'

0 个答案:

没有答案