Self-referential ReferenceProperty in Google App Engine
- by Ink-Jet
I'm having a bit of trouble with ReferencePropertys in App Engine (Python).
For a bit of fun, I'm trying to model a folder/file system, but having trouble getting folders to reference folders.
My first attempt was this:
class Folder(db.Model):
id = db.StringProperty()
name = db.StringProperty()
created = db.DateTimeProperty(auto_now_add=True)
folder = db.ReferenceProperty(Folder, collection_name="folders")
But that fails as "Folder" isn't defined when "folder" is trying to be defined.
I've also tried defining "folder" outside of the main declaration for "Folder", like so:
class Folder(db.Model):
id = db.StringProperty()
name = db.StringProperty()
created = db.DateTimeProperty(auto_now_add=True)
Folder.folder = db.ReferenceProperty(Folder, collection_name="folders")
But that fails with:
AttributeError: 'Folder' object has no attribute 'folders'
I'm kind of stumped. Does anyone have experience with this, or a solution to this problem?
Thanks in advance.