I have a question about flask marshmallow schema. So, I create models like an example below.
class ID(db.Model):
__abstract__ = True
id = db.Column(db.Integer, autoincrement=True, primary_key=True)
class Timestamp(db.Model):
__abstract__ = True
created = db.Column(db.DateTime, default=db.func.now(), nullable=False)
updated = db.Column(
class Checklist(ID, Timestamp):
__tablename__ = "checklist"
partner_id = db.Column(db.Integer(), db.ForeignKey("partner.id"), nullable=False)
statement_status = db.Column(
db.Enum(StatementStatus), nullable=False, default=StatementStatus.NOT_SELECTED
)
statement_accuracy = db.Column(
db.Enum(StatementAccuracy),
nullable=False,
default=StatementAccuracy.NOT_SELECTED,
)
update_status = db.Column(
db.Enum(UpdateStatus), nullable=False, default=UpdateStatus.NOT_SELECTED
)
annual_text_return = db.Column(
db.Enum(AnnualReturnStatus),
nullable=False,
default=AnnualReturnStatus.NOT_SELECTED,
)
Then i have schema like this:
from flask_marshmallow.sqla import SQLAlchemyAutoSchema
class ChecklistSchema(SQLAlchemyAutoSchema):
class Meta:
model = Checklist
include_fk = True
Is it possible to have output enum like
statement_status: {"value": NOT_SELECTED, "name": "Not Selected"}
after I dump? Thx before
Finally I found the answer.
create class that serialize field enum to dict
class EnumToDictionary(fields.Field):