我是ndb的新手。这是我的结构通常的样子:
a = [b, c]
b = [d, e, f]
d = [g, h]
e = [k, l, m, n]
f = [o]
c = [p, r, t]我有以下的模型。
class Child(ndb.Model):
    name = ndb.StringProperty()
    child = ndb.KeyProperty(kind="Child", repeated=True)
class Root(ndb.Model):
    name = ndb.StringProperty()
    child = db.StructuredProperty(Child, repeated=True)我不能这样做,因为ndb不允许我重复,因为我已经重复了Child。
对这种结构进行建模的正确方法是什么?
发布于 2014-06-07 08:27:41
我不明白你为什么要给孩子做KeyProperty检查。你可以这样模拟你的关系:
class Child(ndb.Model):
    name = ndb.StringProperty()
class Root(ndb.Model):
    name = ndb.StringProperty()
    child = ndb.KeyProperty(repeated=True)
c1 = Child(name="b").put()
c2 = Child(name="c").put()
a = Root(child=[c1,c2]).put() # put returns the key; otherwise you would need c1.key() here
children_keys = a.get().child # [Key(Child, 1234), Key(Child, 4567)]
# to retrieve the children, you could do
children = [ key.get() for key in children_keys ]https://stackoverflow.com/questions/23981412
复制相似问题