def ins2dict(ins, kind=''):
    """Turn a SQLAlchemy Model instance to dict.

    :param ins: a SQLAlchemy instance.
    :param kind: specify which kind of dict tranformer should be called.
    :return: dict, instance data.

    If model has defined `to_xxx_dict`, then ins2dict(ins, 'xxx') will
    call `model.to_xxx_dict()`. Default kind is ''.

    If model not defined 'to_dict', then ins2dict will transform according
    by model column definition.
    """
    if kind and hasattr(ins, 'to_%s_dict' % kind):
        return getattr(ins, 'to_%s_dict' % kind)()
    elif hasattr(ins, 'to_dict'):
        return getattr(ins, 'to_dict')()
    else:
        return _turn_row_to_dict(ins)
def ins2dict ( ins , kind = '' ) : if kind and hasattr ( ins , 'to_%s_dict' % kind ) : return getattr ( ins , 'to_%s_dict' % kind ) ( ) elif hasattr ( ins , 'to_dict' ) : return getattr ( ins , 'to_dict' ) ( ) else : return _turn_row_to_dict ( ins )
Turn a SQLAlchemy Model instance to dict.

    :param ins: a SQLAlchemy instance.
    :param kind: specify which kind of dict tranformer should be called.
    :return: dict, instance data.

    If model has defined `to_xxx_dict`, then ins2dict(ins, 'xxx') will
    call `model.to_xxx_dict()`. Default kind is ''.

    If model not defined 'to_dict', then ins2dict will transform according
    by model column definition.