Google App Engine NDB检索浮动属性

时间:2014-07-04 08:21:05

标签: python google-app-engine google-cloud-datastore

如果这个问题有明显的解决方案,我很抱歉,但我一直在努力搜索!

我有一个非常简单的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'>

感谢您花时间帮助,伙计们。

1 个答案:

答案 0 :(得分:1)

您的字段定义错误:您需要实例化该属性。

class UserData(ndb.Model):
    value = ndb.FloatProperty()
相关问题