顺便找了找 5.0.7 orm.py 中, 关于 selection 类型字段的 字段长度处理部分的代码.
[code] if isinstance(f.selection, list) and isinstance(f.selection[0][0], (str, unicode)): f_size = reduce(lambda x, y: max(x, len(y[0])), f.selection, f.size or 16) elif isinstance(f.selection, list) and isinstance(f.selection[0][0], int):
f_size = -1
else:
f_size = (hasattr(f, 'size') and f.size) or 16
if f_size == -1:
f_type = ('int4', 'INTEGER')
else:
f_type = ('varchar', 'VARCHAR(%d)' % f_size)[/code]