0

SqlAlchemy 支持这样的Interval 数据类型

class Sample(Base):
    __tablename__ = "samples"
    id = Column(Integer(), primary_key=True)
    time_interval = Column(Interval(), nullable=True)

是否可以使用 Marshmallow 模式序列化间隔列类型?我希望得到类似以下的东西:

class SampleSchema(Schema):
    id = fields.Int()
    time_interval = fields.Interval(allow_none=True)  # not supported

...但是Marshmallow 不支持区间数据类型。Marshmallow API 文档提到了其他原始数据类型和字符串,但到目前为止我还不能让它工作。

TypeError: Object of type 'timedelta' is not JSON serializable

感谢您提供任何提示或建议。

4

1 回答 1

0

虽然它不提供任何验证,但我能够使用字符串使架构工作:

class SampleSchema(Schema):
    id = fields.Int()
    time_interval = fields.String(allow_none=True)
于 2018-02-07T22:38:10.490 回答