Created
October 20, 2010 10:00
-
-
Save namlook/636126 to your computer and use it in GitHub Desktop.
allow to access Document via the db
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 MyDoc(Document): | |
collection_name = "mydoc" | |
structure = { | |
'foo': unicode, | |
'bar': int, | |
} | |
con = Connection() | |
con.register([MyDoc]) | |
db = con.mydb | |
# this will be allowed and will use the `collection_name` attribute | |
doc = db.MyDoc() | |
# but this is also supported | |
doc = db.mycol.MyDoc() | |
# if the collection is different with the value of `collection_name`, a warning is raised in logging: | |
doc = db.othercol.MyDoc() | |
# Warning : the collection "othercol" is used instead of "mydoc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment