def get_field_type(model, fieldname):
"""Helper which returns the SQLAlchemy type of the field.
"""
field = getattr(model, fieldname)
if isinstance(field, ColumnElement):
fieldtype = field.type
else:
if isinstance(field, AssociationProxy):
field = field.remote_attr
if hasattr(field, 'property'):
prop = field.property
if isinstance(prop, RelProperty):
return None
fieldtype = prop.columns[0].type
else:
return None
return fieldtype
评论列表
文章目录