'Set reference.'

def __set__(self, model_instance, value):

    value = self.validate(value)
    if (value is not None):
        if isinstance(value, datastore.Key):
            setattr(model_instance, self.__id_attr_name(), value)
            setattr(model_instance, self.__resolved_attr_name(), None)
        else:
            setattr(model_instance, self.__id_attr_name(), value.key())
            setattr(model_instance, self.__resolved_attr_name(), value)
    else:
        setattr(model_instance, self.__id_attr_name(), None)
        setattr(model_instance, self.__resolved_attr_name(), None)
