繁体   English   中英

ndb数据存储区给出错误,重复= True和投影

[英]ndb datastore gives me error with repeated=True and projection

我有一个像这样的ndb模型类:

class User(ndb.Model):
    username = ndb.StringProperty()
    works = ndb.StringProperty(repeated=True)
    created_date = ndb.DateTimeProperty(auto_now_add=True)
    updated_date = ndb.DateTimeProperty(auto_now_add=True)

我使用repeated=True因为我想将数据保存到列表中的工作字段。 但是,当我查询这样的工作:

user = User.query().fetch(projection=[User.works])

我无法得到我想要的东西。 如果我看user ,我得到这个:

[User(key=Key('User', 5629499534213120), works=[u'A'], _projection=('works',)), User(key=Key('User', 5629499534213120), works=[u'B'], _projection=('works',)), User(key=Key('User', 5629499534213120), works=[u'C'], _projection=('works',)), User(key=Key('User', 5629499534213120), works=[u'D'], _projection=('works',)).......................

为什么我不能得到这个:

[User(key=Key('User', 5629499534213120), works=[u'A', u'B', u'C', u'D'], _projection=('works',))

我该怎么办? 感谢您的帮助。

投影返回实体列表,而不是您希望的方式。 请看这里: https//developers.google.com/appengine/docs/python/ndb/queries#projection

您可以循环搜索结果:

for u in user:
    print u.works # To get value of 'works'
    print u.key # Key of the entity, you can access other properties from this key.

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM