场景
我们需要对某个数据模型做参数校验, 用于api层的校验和入库前的参数检验,怎么做呢 show code
code
- code
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String, BLOB, TEXT, TIMESTAMP base = declarative_base() class _VideoSeries(base): __tablename__ = 'video_series' series_id = Column(Integer, primary_key=True) series_name = Column(String(255)) f_relevance_id = Column(Integer) f_cp_id = Column(String(255)) f_usage = Column(Integer) f_screen_time = Column(String(16)) status = Column(Integer) f_content_type = Column(Integer) print({i.name: i.type.python_type for i in _VideoSeries.__table__.columns})
- 输出
{'status': <type 'int'>, 'f_usage': <type 'int'>, 'series_name': <type 'str'>, 'f_relevance_id': <type 'int'>, 'series_id': <type 'int'>, 'f_screen_time': <type 'str'>, 'f_content_type': <type 'int'>, 'f_cp_id': <type 'str'>}