Warm tip: This article is reproduced from stackoverflow.com, please click
flask python enums flask-restplus

Python Flask RestPlus Enum Type

发布于 2020-03-27 10:26:54

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'])

Questioner
Ndurere David
Viewed
70
Kobi Dadon 2018-02-17 00:02

You can assign the member names to it:

fields.String(description='The object type', enum=EnumGender._member_names_)