Appengine参考订单

时间:2009-11-26 16:16:22

标签: python django django-models

我在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类也会发生同样的情况。怎么解决这个问题?

感谢。

1 个答案:

答案 0 :(得分:2)

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

请参阅:

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

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