【问题标题】:Google App Engine NDB Retrieving Float PropertyGoogle App Engine NDB 检索浮点属性
【发布时间】: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


    【解决方案1】:

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

    class UserData(ndb.Model):
        value = ndb.FloatProperty()
    

    【讨论】:

    • 天啊,我太笨了。承认这花了我多长时间很痛苦!非常感谢:-)
    • 别担心,最难发现的总是小事。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    • 2012-04-12
    相关资源
    最近更新 更多