Skip to content

Instantly share code, notes, and snippets.

@skyl
Created June 3, 2010 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyl/423540 to your computer and use it in GitHub Desktop.
Save skyl/423540 to your computer and use it in GitHub Desktop.
djongobjomposition
from django.db import models
from mymongo.models import Mongo
class M(models.Model):
...
mongo = Mongo()
>>> type(M.mongo)
<class 'mymongo.models.Collection'>
>>> M.mongo._collection
Collection(Database(Connection('localhost', 27017), u'app_label'), u'module_name')
>>> m = M.objects.get(...)
>>> m.pk
4
>>> type(m.mongo)
<class 'mymongo.models.Document'>
>>> m.mongo # acts as much like a dict as possible
{'_id': 4}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment