how to serialise a enum property in sqlalchemy using marshmallow

后端 未结 3 1282
感情败类
感情败类 2021-01-12 02:01

this is my model class

class Type(enum.Enum):
    Certified = \"certified\"
    Non_Certified = \"non-certified\"


class Status(enum.Enum):
    Approved = \         


        
3条回答
  •  借酒劲吻你
    2021-01-12 02:22

    You can use Marshmallow custom method fields

    from marshmallow import fields
    
    class CourseSchema(ModelSchema):
        type = fields.Method("get_course_type")
    
        def get_course_type(self, obj):
            return obj.type.value
    
        class Meta:
            model = Course
            sqla_session = session
    

提交回复
热议问题