开发者

Creating a model that references itself with Google App Engine

开发者 https://www.devze.com 2023-01-04 15:02 出处:网络
I tried doing the following class SomeModel(db.Model): prev = db.ReferenceProperty(SomeModel) next = db.ReferenceProperty(SomeModel)

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')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号