def get_field_type(column):
"""
Returns the field type to be used determined by the sqlalchemy column type or the column type's python type
"""
if isinstance(column.type, sqltypes.Enum) and not column.type.enum_class:
return fields.ChoiceField
if isinstance(column.type, postgresql.ARRAY):
child_field = SERIALIZER_FIELD_MAPPING.get(column.type.item_type.__class__
) or SERIALIZER_FIELD_MAPPING.get(column.type.item_type.python_type)
if child_field is None:
raise KeyError("Could not figure out field for ARRAY item type '{}'".format(column.type.__class__))
class ArrayField(fields.ListField):
"""Nested array field for PostreSQL's ARRAY type"""
def __init__(self, *args, **kwargs):
kwargs['child'] = child_field()
super(ArrayField, self).__init__(*args, **kwargs)
return ArrayField
if column.type.__class__ in SERIALIZER_FIELD_MAPPING:
return SERIALIZER_FIELD_MAPPING.get(column.type.__class__)
if issubclass(column.type.python_type, bool):
return fields.NullBooleanField if column.nullable else fields.BooleanField
return SERIALIZER_FIELD_MAPPING.get(column.type.python_type)
评论列表
文章目录