def _conv_to_dict(self, obj):
    if isinstance(obj, dict):
        return _clean_dict(obj)
    elif hasattr(obj, 'to_dict'):
        return obj.to_dict()
    elif hasattr(obj, '_to_dict'):
        if (hasattr(obj, '_isinstance') and obj._isinstance):
            if hasattr(obj.__class__, '_subdocument'):
                raise ValueError('Subdocument cannot be added directly')
            return obj._obj_to_dict()
        else:
            return obj._to_dict()
    else:
        raise ValueError('Object cannot convert to dictionary')
def _conv_to_dict(self, obj):
    if isinstance(obj, dict):
        return _clean_dict(obj)
    elif hasattr(obj, 'to_dict'):
        return obj.to_dict()
    elif hasattr(obj, '_to_dict'):
        if (hasattr(obj, '_isinstance') and obj._isinstance):
            if hasattr(obj.__class__, '_subdocument'):
                raise ValueError('Subdocument cannot be added directly')
            return obj._obj_to_dict()
        else:
            return obj._to_dict()
    else:
        raise ValueError('Object cannot convert to dictionary')