I have a function to add a column to a model:
def col(_type, label = "", **kwargs):
c = db.Column(_type, **kwargs)
c.info = {"label":label, "type":""}
return c
I use it like:
# Job Type
class JTEnum(enum.Enum):
full = "ﺖﻣﺎﻣ ﻮﻘﺗ"
part_time = "ﻦﯿﻤﻫ ﻮﻘﺗ"
project = "ﭖﺭﻭﮋﻫ ﺎﯾ"
jobtype = col(db.Enum(JTEnum), "ﻥﻮﻋ ﺶﻐﻟ", unique=False,
nullable=False,
default=JTEnum.full.name)
jobtype.info["choices"] = [(i.name, i.value) for i in JTEnum]
I call the col function for various columns. I would like to put the last line inside this function and it can be called on Enum type and fill the choices something like:
def col(_type, label = "", **kwargs):
c = db.Column(_type, **kwargs)
c.info = {"label":label, "type":""}
if isinstance(_type, db.Enum):
c.info["choices"] = [(i.name, i.value) for i in _type]
return c
However, it gives the error:
TypeError: 'Enum' object is not iterable
_typewhich isdb.Enumis not iterable. You may refer toa.type.enum_classlike that:[(i.name, i.value) for i in a.type.enum_class].