【发布时间】:2013-01-10 14:51:40
【问题描述】:
对于以下(损坏的)函数,如果实体已创建或更新,我想返回True,否则返回False。问题是我不知道get_or_insert() 是否获得了现有实体,或者插入了一个。有没有简单的方法来确定这一点?
class MyModel(ndb.Model):
def create_or_update(key, data):
"""Returns True if entity was created or updated, False otherwise."""
current = MyModel.get_or_insert(key, data=data)
if(current.data != data)
current.data = data
return True
return False
【问题讨论】:
标签: python google-app-engine app-engine-ndb