Ian Burris
Ian Burris

Reputation: 6515

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

Is there a way of doing this?

Upvotes: 5

Views: 96

Answers (2)

Paul
Paul

Reputation: 273

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

Upvotes: 0

Adam Crossland
Adam Crossland

Reputation: 14213

Yes, you can use a SelfReferenceProperty

class SomeModel(db.Model):
    prev = db.SelfReferenceProperty()
    next = db.SelfReferenceProperty()

Upvotes: 5

Related Questions