This is a follow up to the very interesting answers of best-way-to-do-enum-in-sqlalchemy. Cito extends Zzzeeks answer to include ordering which is very nice. Cito also leaves a tantalizing bit of code near the end.
class DeclEnumType(SchemaType, TypeDecorator):
"""DeclEnum augmented so that it can persist to the database."""
This is exactly what I am attempting to do build a Python Enum that is represented in its own table in the db. Where the EmployeeType.full_time is usable in Python code and has its own table in the DB (for this simple example just a idx and name).
However, I'm not sure I understand how to use Cito's DeclEnumType example as the following doesn't create a EmployeeType table in the database.
class EmployeeType(DeclEnum):
# order will be as stated: full_time, part_time, contractor
full_time = EnumSymbol("Full Time")
part_time = EnumSymbol("Part Time")
contractor = EnumSymbol("Contractor")
class Employee(Base):
__tablename__ = 'employee'
id = Column(Integer, primary_key=True)
name = Column(String(60), nullable=False)
type = Column(DeclEnumType(EmployeeType))
Any ideas on how to get this dual representation?