AttributeError:'Query'对象没有属性'has_key'

时间:2016-10-21 20:29:05

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

我已将表定义更改为使用Reference Property。现在当我尝试插入时,如果value不是None而不是value.has_key():AttributeError:'Query'对象没有属性'has_key'

subject = self.request.get('subject')
    content = self.request.get('content')
    user = self.request.get('name')
    name = User.all().filter('name =', user)

    if subject and content:
        p = Post(parent = blog_key(), subject = subject, content = content, user = name)

        p.put()

这是我的Post类

class Post(db.Model):
subject = db.StringProperty(required = True)
content = db.TextProperty(required = True)
created = db.DateTimeProperty(auto_now_add = True)
last_modified = db.DateTimeProperty(auto_now = True)
user = db.ReferenceProperty(User)

我正在使用Python 2.7。我试图按照另一个帖子的说明,关于值是否为None而不是value.has_key():但这些建议对我没用。

1 个答案:

答案 0 :(得分:0)

感谢大家的帮助。

我添加了,然后将名称设为p。

    for p in q.run():
        print  "name ", p.name

    if subject and content:
        p = Post(parent = blog_key(), subject = subject, content = content, name = p)