this is my model class
class Type(enum.Enum):
Certified = \"certified\"
Non_Certified = \"non-certified\"
class Status(enum.Enum):
Approved = \
For enum fields, the simplest approach is to install the package called marshmallow_enum
via pip (pip install marshmallow_enum
), importing it in your project and then in your marshmallow schema definitions override the SQLAlchemy fields with your custom definition:
from marshmallow_enum import EnumField
...
class CourseSchema(ModelSchema):
type = EnumField(Type, by_value=True)
class Meta:
model = Course
sqla_session = session
All fields that weren't overridden by your custom definitions will be taken from your model.
You can experiment with the by_value
parameter, which enables you to either serialize names (by default) or values (by_value=True
) of your enums.