Created
March 21, 2012 21:30
-
-
Save j2labs/2153051 to your computer and use it in GitHub Desktop.
New DictShield metaclass system
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
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