我在AppEngine的models.py中声明了模型:

class Post(db.Model):
topic = db.ReferenceProperty(Topic, collection_name='posts', verbose_name=_('Topic'))
(..)

class Topic(db.Model):
(..)
last_post = db.ReferenceProperty(Post, collection_name='last_topic_post')

问题是ReferenceProperty必须具有Model类,但在声明Post时未声明Topic类。切换后Post类也会发生同样的情况。怎么解决这个问题?

感谢。

有帮助吗?

解决方案

ReferenceProperty接受None代替模型类,这意味着“没有类型限制”。在那个领域。然而,这不是一个好的解决方案。

请参阅:

http://code.google.com/appengine /docs/python/datastore/typesandpropertyclasses.html#ReferenceProperty

在你的模型中有这样的循环引用并不是一个好主意恕我直言。您应该根据需要找到 last_post ,而不是存储对它的引用。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top