对单个事务中多个实体的更改

2024-04-20 03:57:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在appengine平台中对单个事务中的多个实体进行更改。据我所知,为了成功地做到这一点,appengine需要提前知道哪些实体将一起更新,因此它知道以支持事务的方式存储它们。因此,在创建实体时,用户必须声明一个实体与另一个实体属于同一个实体组。你知道吗

如何在创建时声明一个实体属于另一个实体组?你知道吗


Tags: 用户实体声明方式平台事务appengine
2条回答

只需将第一类的obj作为第二类构造函数的父参数。。。你知道吗

就像

class GroupA(db.Model):
    counterA = db.IntegerProperty()

class ExampleA(db.Model):
    exampleA = db.IntegerProperty()

def increment_counterA():

    obj = GroupA()
    obj.counterA = '89'
    obj.put()

    obj1 = ExampleA(parent = obj)
    obj1.exampleA = 90
    obj1.put()

class implementGroupA(webapp.RequestHandler):
    def get(self):
        db.run_in_transaction(increment_counterA)


def main():
    application = webapp.WSGIApplication([('/', implementGroupA)],
                                         debug=True)
    util.run_wsgi_app(application)

if __name__ == '__main__':
    main()

使用parent参数为构造函数建模

相关问题 更多 >