title: SQLAlchemy Enums Code Representation _and_ DB Representation
body: <p>This is a follow up to the very interesting answers of <a href="https://stackoverflow.com/questions/2676133/best-way-to-do-enum-in-sqlalchemy">best-way-to-do-enum-in-sqlalchemy</a>.  Cito extends Zzzeeks answer to include ordering which is very nice.  Cito also leaves a tantalizing bit of code near the end.</p>
  
  <pre><code>class DeclEnumType(SchemaType, TypeDecorator):
      """DeclEnum augmented so that it can persist to the database."""
  </code></pre>
  
  <p>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 <em>and</em> has its own table in the DB (for this simple example just a idx and name).</p>
  
  <p>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.</p>
  
  <pre><code>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))
  </code></pre>
  
  <p>Any ideas on how to get this dual representation?</p>