#NEWLINE# def __new__( cls , name , bases , attrs ) : #NEWLINE# #INDENT# '\n        Checks for an inner ``Meta`` class with a ``mixin_for``\n        attribute containing the model that this model will be mixed\n        into. Once found, copy over any model fields and methods onto\n        the model being mixed into, and return it as the actual class\n        definition for the mixin.\n        ' #NEWLINE# if ( name == 'ModelMixin' ) : #NEWLINE# #INDENT# return super ( ModelMixinBase , cls ) . __new__ ( cls , name , bases , attrs ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# mixin_for = attrs . pop ( 'Meta' ) . mixin_for #NEWLINE# if ( not issubclass ( mixin_for , Model ) ) : #NEWLINE# #INDENT# raise TypeError #NEWLINE# #UNINDENT# #UNINDENT# except ( TypeError , KeyError , AttributeError ) : #NEWLINE# #INDENT# 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." ) #NEWLINE# #UNINDENT# for ( k , v ) in attrs . items ( ) : #NEWLINE# #INDENT# if isinstance ( v , Field ) : #NEWLINE# #INDENT# v . contribute_to_class ( mixin_for , attrs ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( k != '__module__' ) : #NEWLINE# #INDENT# setattr ( mixin_for , k , v ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return mixin_for