python-flask-SQLAlchemy-Utils组件
SQLAlchemy-Utils,提供choice功能 定义: # pip3 install sqlalchemy-utils from sqlalchemy_utils import ChoiceType Base = declarative_base() class Xuan(Base): __tablename__ = 'xuan' types_choices = ( (1,'欧美'), (2,'日韩'), (3,'老男孩'), ) id = Column(Integer,primary_key=True,autoincrement=True) name = Column(String(64)) types = Column(ChoiceType(types_choices,Integer())) __table_args__ = { 'mysql_engine':'Innodb', 'mysql_charset':'utf8', } 查询: result_list = session.query(Xuan).all() for item in result_list: print(item.types.code,item.types.value)