Skip to content

Instantly share code, notes, and snippets.

@namlook
Created October 20, 2010 09:56
Show Gist options
  • Save namlook/636121 to your computer and use it in GitHub Desktop.
Save namlook/636121 to your computer and use it in GitHub Desktop.
Allow documents to self-reference
class Doc(Document):
structure = {
"connections": [ SELF ],
"some": unicode,
"other": unicode,
"important": int,
"data": uncode,
}
a = db.test.Doc()
a.save()
b = db.test.Doc()
b.save()
c = db.test.Doc()
c.save()
a.connections = [ b, c ]
a.save()
b.connections = [ a, c ]
b.save()
# now:
s = a.connections[1].some
x = [ i.important for i in b.connections ]
x2 = db.test.Doc.find({ "connections": { "$in": [ b ] }})
#etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment