def __new__(cls, name, bases, attrs):
        formfield_callback = attrs.pop('formfield_callback', None)
        try:
            parents = [
                b for b in bases
                if issubclass(b, DocumentForm) or
                issubclass(b, EmbeddedDocumentForm)
            ]
        except __HOLE__:
            # We are defining DocumentForm itself.
            parents = None
        new_class = super(DocumentFormMetaclass, cls).__new__(cls, name,
                                                              bases, attrs)
        if not parents:
            return new_class

        if 'media' not in attrs:
            new_class.media = media_property(new_class)

        opts = new_class._meta = ModelFormOptions(
            getattr(new_class, 'Meta', None)
        )
        if opts.document:
            formfield_generator = getattr(opts,
                                          'formfield_generator',
                                          _fieldgenerator)

            # If a model is defined, extract form fields from it.
            fields = fields_for_document(opts.document, opts.fields,
                                         opts.exclude, opts.widgets,
                                         formfield_callback,
                                         formfield_generator)
            # make sure opts.fields doesn't specify an invalid field
            none_document_fields = [k for k, v in fields.items() if not v]
            missing_fields = (set(none_document_fields) -
                              set(new_class.declared_fields.keys()))
            if missing_fields:
                message = 'Unknown field(s) (%s) specified for %s'
                message = message % (', '.join(missing_fields),
                                     opts.model.__name__)
                raise FieldError(message)
            # Override default model fields with any custom declared ones
            # (plus, include all the other declared fields).
            fields.update(new_class.declared_fields)
        else:
            fields = new_class.declared_fields

        new_class.base_fields = fields
        return new_class
dataset/ETHPy150Open jschrewe/django-mongodbforms/mongodbforms/documents.py/DocumentFormMetaclass.__new__