Appengine reference order
-
05-07-2019 - |
Question
I have declared models in AppEngine's 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')
Problem is ReferenceProperty must have Model class but Topic class is undeclared when declaring Post. The same will happen with Post class after switch. How to solve this?
Thanks.
Solution
ReferenceProperty accepts None in place of a model class, which means "no type restriction" on that field. It is not a nice solution, however.
See:
Having such cyclic references in your model is not a good idea IMHO. You should find your last_post
on demand instead of storing a reference to it.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow