Skip to content

Instantly share code, notes, and snippets.

@j2labs
Created March 21, 2012 21:30
Show Gist options
  • Save j2labs/2153051 to your computer and use it in GitHub Desktop.
Save j2labs/2153051 to your computer and use it in GitHub Desktop.
New DictShield metaclass system
from dictshield.document import Document, EmbeddedDocument
from dictshield.fields import StringField, UUIDField
from dictshield.fields.mongo import ObjectIdField
class ThoughtsMixin(EmbeddedDocument):
"""Simple document that has one StringField member
"""
thoughts = StringField(max_length=255)
class Meta:
mixin = True
class Media(Document, ThoughtsMixin):
"""Simple document that has one StringField member
"""
owner = ObjectIdField()
title = StringField(max_length=40)
class Meta:
id_field = ObjectIdField
id_options = {'auto_fill': True}
m1 = Media()
m2 = Media()
m1.title = 'Some Title'
m1.thoughts = 'Here are my thoughts about something'
print m1.to_json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment