added global model registry and GenericReferenceField, a ReferenceField not bound to a particular model
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user