(self, key, value)
1) If setting :attr:`wrapped` attribute, point parent to this object (the ModelWrapper).
        2) Setting attributes in the right objects. The following rules are processed in order:
           (a) If attribute exists in wrapper, set in wrapper.
           (b) If no object has been wrapped (wrapper is None), set attribute in the wrapper.
           (c) If attribute is found in the wrapped object, set it there. This rule is ignored for AF storages.
           (d) Set attribute in wrapper.
1) If setting :attr:`wrapped` attribute, point parent to this object (the ModelWrapper).
        2) Setting attributes in the right objects. The following rules are processed in order:
           (a) If attribute exists in wrapper, set in wrapper.
           (b) If no object has been wrapped (wrapper is None), set attribute in the wrapper.
           (c) If attribute is found in the wrapped object, set it there. This rule is ignored for AF storages.
           (d) Set attribute in wrapper.
1 ) If setting : attr : wrapped attribute point parent to this object ( the ModelWrapper ) . 2 ) Setting attributes in the right objects . The following rules are processed in order : ( a ) If attribute exists in wrapper set in wrapper . ( b ) If no object has been wrapped ( wrapper is None ) set attribute in the wrapper . ( c ) If attribute is found in the wrapped object set it there . This rule is ignored for AF storages . ( d ) Set attribute in wrapper .
def __setattr__(self, key, value):
        """
        1) If setting :attr:`wrapped` attribute, point parent to this object (the ModelWrapper).
        2) Setting attributes in the right objects. The following rules are processed in order:
           (a) If attribute exists in wrapper, set in wrapper.
           (b) If no object has been wrapped (wrapper is None), set attribute in the wrapper.
           (c) If attribute is found in the wrapped object, set it there. This rule is ignored for AF storages.
           (d) Set attribute in wrapper.
        """
        if key is 'wrapped':
            object.__setattr__(self, key, value)
            value.__setattr__('_parent', self)
            return

        try:
            # If attribute is in this object, set it. Test by using getattribute instead of hasattr to avoid lookup in
            # wrapped object.
            self.__getattribute__(key)
            super(ModelWrapper, self).__setattr__(key, value)
        except AttributeError:
            # Attribute is not in wrapper.
            # In case no wrapped object is set yet (e.g. constructor), set in wrapper.
            if 'wrapped' not in self.__dict__:
                super(ModelWrapper, self).__setattr__(key, value)
                return

            if hasattr(self, key):
                # Now use hasattr, we know getattribute already failed so if it returns true, it must be in the wrapped
                # object. Hasattr is called on self instead of self.wrapped to account for the different handling of
                # AF storages.
                # Prefer setting the attribute in the wrapped object if exists.
                setattr(self.wrapped, key, value)
            else:
                #  If not, set in wrapper nonetheless.
                super(ModelWrapper, self).__setattr__(key, value)
def __setattr__ ( self , key , value ) : if key is 'wrapped' : object . __setattr__ ( self , key , value ) value . __setattr__ ( '_parent' , self ) return try : # If attribute is in this object, set it. Test by using getattribute instead of hasattr to avoid lookup in # wrapped object. self . __getattribute__ ( key ) super ( ModelWrapper , self ) . __setattr__ ( key , value ) except AttributeError : # Attribute is not in wrapper. # In case no wrapped object is set yet (e.g. constructor), set in wrapper. if 'wrapped' not in self . __dict__ : super ( ModelWrapper , self ) . __setattr__ ( key , value ) return if hasattr ( self , key ) : # Now use hasattr, we know getattribute already failed so if it returns true, it must be in the wrapped # object. Hasattr is called on self instead of self.wrapped to account for the different handling of # AF storages. # Prefer setting the attribute in the wrapped object if exists. setattr ( self . wrapped , key , value ) else : #  If not, set in wrapper nonetheless. super ( ModelWrapper , self ) . __setattr__ ( key , value )