如何更新谷歌应用引擎中的数据 - Python?

gat*_*ath 0 python google-app-engine

如何在Google应用引擎中更新我的记录?

我的模型包含以下字段

doc_no = db.IntegerProperty()
title = db.StringProperty()
level = db.StringProperty()
Run Code Online (Sandbox Code Playgroud)

我想要的是更新字段标题和级别,但我想通过像JavaScript对象的字符串访问属性/属性,即

如果我选择模型

myRecord = db.GQLQuery('Select * from MyModelAbove where doc_no = 1')
Run Code Online (Sandbox Code Playgroud)

是否可以访问和更新这样的属性;

myRecord['title']='New Tile'
myRecord['level']='Level2'
myRecord.put()
Run Code Online (Sandbox Code Playgroud)

我见过的就是这个(不适合我);

myRecord.title = 'New Title'
Run Code Online (Sandbox Code Playgroud)

注意:顺便说一句谷歌文档在这个领域是非常少的

gre*_*reg 7

在您的代码示例中,myRecords是一个查询.您必须在修改前获得结果:

result = myRecords.get()
Run Code Online (Sandbox Code Playgroud)

然后,如果您不能或不想访问title属性result.title,则可以使用setattr(result, 'title', 'New Title')thenresult.put()