【问题标题】:How to query entities without no ancestors in appengine python如何在appengine python中查询没有祖先的实体
【发布时间】:2015-11-12 07:15:48
【问题描述】:

考虑以下代码sn-p:

from google.appengine.ext import ndb
import pprint

class Entity(ndb.Model):
     name = ndb.StringProperty()
     age = ndb.IntegerProperty()

entity = Entity()
entity.name = "hello"
entity.age = 23
entity.key = ndb.Key(Entity, "p1")
entity.put()

e2 = Entity()
e2.key = ndb.Key(Entity, "p2", parent=ndb.Key(Entity, "p1"))
e2.name = "he11o2"
e2.age = 34
e2.put()

我想查询没有任何记录的Entity表 与之关联的父级。对于上面的示例,它应该只产生 p1 实体。

我怎样才能做到这一点?

【问题讨论】:

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


    【解决方案1】:

    你不能。您只能查询存在于索引中的事物。除非明确设置为 None(你不能为父母这样做),否则没有价值的东西不能被查询。

    我可以建议的唯一方法是,如果没有父键或父键或标志,则将计算属性或其他一些属性设置为 None。然后您可以查询所有具有 parent=None 的实体。 parent 是实体的属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多