Skip to content

Instantly share code, notes, and snippets.

@namlook
Created October 20, 2010 09:43
Show Gist options
  • Save namlook/636106 to your computer and use it in GitHub Desktop.
Save namlook/636106 to your computer and use it in GitHub Desktop.
A '_type' field that can be used to automatically case documents
from mongokit import *
import numpy as np
class MongoMatrix(Document):
structure = {}
use_autorefs = True
use_dot_notation=True
atomic_save = True
class Test(MongoMatrix):
structure = {'new':unicode}
class Run(Document):
structure = {'title':unicode,
'result': MongoMatrix, }
use_autorefs = True
use_dot_notation=True
atomic_save = True
connection = Connection()
connection.register([Run, MongoMatrix, Test])
run = connection.test.example.Run()
test1 = connection.test.example.Test()
test1.new=u'we'
test1.save()
run.result = test1
run.save()
#The first save above will convert run.result into its base class
#When you save it again, the run.result base class is called and
#verification fails with:
#structureError: unknown fields : [u'new']
run.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment