Skip to content

Instantly share code, notes, and snippets.

@cbednarski
Last active December 20, 2015 21:38
Show Gist options
  • Save cbednarski/6198582 to your computer and use it in GitHub Desktop.
Save cbednarski/6198582 to your computer and use it in GitHub Desktop.
pymongo collections and data binding
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