Created
February 10, 2014 11:40
-
-
Save kibernick/8914403 to your computer and use it in GitHub Desktop.
MongoDB in Python through MongoEngine - playing with DynamicDocuments and instantiating different types of Documents in the same collection
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 mongoengine import Document, DynamicDocument | |
class AppelateCase(Document): | |
appelate_blob = StringField() | |
class BankruptcyCase(Document): | |
bankrupcy_blob = StringField() | |
class MyCase(DynamicDocument): | |
type = StringField() | |
@classmethod | |
def from_appelate(cls, appelate_case): | |
mc = cls.from_json(appelate_case.to_json()) | |
mc.type = "AppelateCase" | |
return mc | |
@classmethod | |
def from_bankrupcy(cls, bankrupcy_case): | |
mc = cls.from_json(bankrupcy_case.to_json()) | |
mc.type = "BankruptcyCase" | |
return mc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment