Creating a model that references itself with Google App Engine
I tried doing the following
class SomeModel(db.Model):
prev = db.ReferenceProperty(SomeModel)
next = db.ReferenceProperty(SomeModel)
but got the following error
NameError: name 'TrackPointModel' is not defined
I开发者_如何学JAVAs there a way of doing this?
Yes, you can use a SelfReferenceProperty
class SomeModel(db.Model):
prev = db.SelfReferenceProperty()
next = db.SelfReferenceProperty()
Doesn't having a, say, next property make the prev property superfluous? If I'm not mistaken this works equally well:
class SomeModel(db.Model):
next = db.SelfReferenceProperty(collection_name='prev')
精彩评论