Last active
December 20, 2015 21:38
-
-
Save cbednarski/6198582 to your computer and use it in GitHub Desktop.
pymongo collections and data binding
This file contains hidden or 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 MongoModel(object): | |
| def __init__(**kwargs): | |
| for key, value in kwargs.iteritems(): | |
| # self.__dict__[key] = value | |
| setattr(self, key, value) | |
| class MongoList(object): | |
| def __init__(): | |
| if not self._type: | |
| self._type = self.__name__[:-1] | |
| def find(query): | |
| for record in db[self._type].find(query): | |
| record_object = self._type(record) | |
| yield record_object | |
| class BlogPosts(MongoList): | |
| class BlogPonies(MongoList): | |
| _type = 'BlogPony' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment