简体   繁体   English

同一实体的数据存储区父级子级

[英]Datastore parent child of the same entity

I would like to have a datastore entity with a reference property back to the same entity. 我希望有一个具有引用属性的数据存储区实体回到同一实体。 For example: 例如:

class Person(db.Model):
    name = db.StringProperty(),
    parent = db.ReferenceProperty(Person,
            collection_name='parents')

So a person has a parent who is also a person (hopefully). 因此,一个人的父母(也是希望的)也是一个人。 This throws a NameError: name 'Person' is not defined exception. 这将引发NameError: name 'Person' is not defined异常。 This example would only allow a person to have one parent, but it is just an example, not exactly what I am trying to model. 这个例子只允许一个人有一个父母,但这只是一个例子,并不完全是我要建模的东西。

What is the best way to model this type of relationship with google app engine datastore? 用Google App Engine数据存储区建立这种关系的最佳方法是什么?

采用:

parent = db.SelfReferenceProperty(collection_name='parents')

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

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