added global model registry and GenericReferenceField, a ReferenceField not bound to a particular model

This commit is contained in:
blackbrrr
2010-02-26 16:59:12 -06:00
parent 200e9eca92
commit 03d31b1890
3 changed files with 160 additions and 7 deletions

View File

@@ -3,9 +3,13 @@ from queryset import QuerySet, QuerySetManager
import pymongo
_model_registry = {}
class ValidationError(Exception):
pass
class BaseField(object):
"""A base class for fields in a MongoDB document. Instances of this class
may be added to subclasses of `Document` to define a document's schema.
@@ -158,6 +162,8 @@ class TopLevelDocumentMetaclass(DocumentMetaclass):
"""
def __new__(cls, name, bases, attrs):
global _model_registry
super_new = super(TopLevelDocumentMetaclass, cls).__new__
# Classes defined in this package are abstract and should not have
# their own metadata with DB collection, etc.
@@ -246,6 +252,8 @@ class TopLevelDocumentMetaclass(DocumentMetaclass):
new_class._meta['id_field'] = 'id'
new_class.id = new_class._fields['id'] = ObjectIdField(name='_id')
_model_registry[name] = new_class
return new_class