【发布时间】:2014-07-04 08:21:04
【问题描述】:
如果这个问题有明显的解决方案,我很抱歉,但我整天都在努力搜索!
我有一个非常简单的 NDB 模型:
class UserData(ndb.Model):
value = ndb.FloatProperty
现在,如果实体尚不存在,我将使用以下内容添加它。否则,我现在只记录它:
features = json.loads(self.request.get("features"))
for field in features:
val = float(features[field])
key = ndb.Key("user", user, "model", "1", "param", field)
res = UserData.query(ancestor=key)
if res.count() > 0:
param = res.fetch()[0]
print "currentVal = " + str(param.value)
else:
newparam = UserData(parent=key)
newparam.value = 1.0
newparam.put()
添加值可以正常工作,但打印行会输出以下内容:
currentVal = <class 'google.appengine.ext.ndb.model.FloatProperty'>
感谢您抽出宝贵时间提供帮助,伙计们。
【问题讨论】:
标签: python google-app-engine google-cloud-datastore