def __new__(cls, name, bases, attrs):
        """
        Checks for an inner ``Meta`` class with a ``mixin_for``
        attribute containing the model that this model will be mixed
        into. Once found, copy over any model fields and methods onto
        the model being mixed into, and return it as the actual class
        definition for the mixin.
        """
        if name == "ModelMixin":
            # Actual ModelMixin class definition.
            return super(ModelMixinBase, cls).__new__(cls, name, bases, attrs)
        try:
            mixin_for = attrs.pop("Meta").mixin_for
            if not issubclass(mixin_for, Model):
                raise TypeError
        except (TypeError, KeyError, AttributeError):
            raise ImproperlyConfigured("The ModelMixin class '%s' requires "
                                       "an inner Meta class with the "
                                       "``mixin_for`` attribute defined, "
                                       "with a value that is a valid model.")
        # Copy fields and methods onto the model being mixed into, and
        # return it as the definition for the mixin class itself.
        for k, v in attrs.items():
            if isinstance(v, Field):
                v.contribute_to_class(mixin_for, k)
            elif k != "__module__":
                setattr(mixin_for, k, v)
        return mixin_for
def __new__ ( cls , name , bases , attrs ) : if name == "ModelMixin" : return super ( ModelMixinBase , cls ) . __new__ ( cls , name , bases , attrs ) try : mixin_for = attrs . pop ( "Meta" ) . mixin_for if not issubclass ( mixin_for , Model ) : raise TypeError except ( TypeError , KeyError , AttributeError ) : raise ImproperlyConfigured ( "The ModelMixin class '%s' requires " "an inner Meta class with the " "``mixin_for`` attribute defined, " "with a value that is a valid model." ) for k , v in attrs . items ( ) : if isinstance ( v , Field ) : v . contribute_to_class ( mixin_for , k ) elif k != "__module__" : setattr ( mixin_for , k , v ) return mixin_for
Checks for an inner ``Meta`` class with a ``mixin_for``
        attribute containing the model that this model will be mixed
        into. Once found, copy over any model fields and methods onto
        the model being mixed into, and return it as the actual class
        definition for the mixin.