def __new__(cls, name, bases, attr):
    if (name == 'Models'):
        return type.__new__(cls, name, bases, attr)
    table_name = attr.get('table_name', None)
    if (not table_name):
        table_name = name
    primary_key = None
    mappings = dict()
    for (k, v) in attr.items():
        if isinstance(v, BaseField):
            mappings[k] = v
            if v.primary_key:
                if primary_key:
                    raise TypeError('主键重复')
                primary_key = k
    for k in mappings.keys():
        attr.pop(k)
    if (not primary_key):
        raise TypeError('没有主键')
    attr['mappings'] = mappings
    attr['primary_key'] = primary_key
    attr['table_name'] = table_name
    return type.__new__(cls, name, bases, attr)
def __new__(cls, name, bases, attr):
    if (name == 'Models'):
        return type.__new__(cls, name, bases, attr)
    table_name = attr.get('table_name', None)
    if (not table_name):
        table_name = name
    primary_key = None
    mappings = dict()
    for (k, v) in attr.items():
        if isinstance(v, BaseField):
            mappings[k] = v
            if v.primary_key:
                if primary_key:
                    raise TypeError('主键重复')
                primary_key = k
    for k in mappings.keys():
        attr.pop(k)
    if (not primary_key):
        raise TypeError('没有主键')
    attr['mappings'] = mappings
    attr['primary_key'] = primary_key
    attr['table_name'] = table_name
    return type.__new__(cls, name, bases, attr)