更新应用程序引擎实体
如何在应用引擎中更新已有的记录。
4 个回答
2
我使用GQL来查询一个实体,如果这个实体存在,就更新它的属性。
result = db.GqlQuery('select name from Person where name = "tadeu"')
if result:
for r in result:
r.attribute = "value"
r.put()
41
只要一个实体有定义的键,它就会在put()
操作时被更新:
record = Record(value='foo')
# This creates a new record
record.put()
record.value = 'shmoo'
# This updates it
record.put()
key = record.key()
record2 = Record.get(key)
record2.value = 'bar'
# Yet again this updates the same record
record2.put()
-3
如果你能使用数据存储的话,可以用gql。你需要根据你的数据库类来定义更新的方法。更新操作只能通过这个类来进行,并且需要通过请求来调用。