Am using python 3.4.
I have created an enum
type as shown below:
import enum
class EnumGender(enum.Enum):
blank = ' '
female = 'Female'
male = 'Male'
other = 'Other'
my question is how do i assign it to flask-restplus field as the only examples i can see are:
fields.String(description='The object type', enum=['A', 'B'])
You can assign the member names to it:
fields.String(description='The object type', enum=EnumGender._member_names_)
Is it possible to use a enum.IntEnum with fields.Integer?
Docs tell me that there is no
Enum._member_names_
but there isEnum.__members__
which is a view. So you'll have to dofields.String(description='The object type', enum=EnumGender.__members__.items())
. A little verbose.For me _members__items() throws unserializable error, although _member_names is protected but it works.