SQLAlchemy-Utils,提供choice功能
时间:2021-07-01 10:21:17
帮助过:16人阅读
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)
SQLAlchemy-Utils,提供choice功能
标签:types import lis list blog har choices span session