Created
October 20, 2010 09:56
-
-
Save namlook/636121 to your computer and use it in GitHub Desktop.
Allow documents to self-reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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