Self-referential ReferenceProperty in Google App Engine
Posted
by Ink-Jet
on Stack Overflow
See other posts from Stack Overflow
or by Ink-Jet
Published on 2010-04-03T14:31:06Z
Indexed on
2010/04/03
14:33 UTC
Read the original article
Hit count: 246
python
|google-app-engine
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.
© Stack Overflow or respective owner