views:

79

answers:

2

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.

A: 

Try to put the Topic and Object in quotes.

EDIT: Mistook it for a ForeignKey where one can use the name of the model rather than the model object itself when it has not been defined yet. Sorry.

Jannis
A: 

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:

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

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.

fviktor