Skip to content Skip to sidebar Skip to footer

Marshmallow Result Customization

I have the sqlalchemy model with jsonb field and marshmallow schema for this model: class Settings(db.Model): id = db.Column(UUID, primary_key=True, server_d

Solution 1:

I've got it. I should been used @post_dump in my schema:

class SettingsSchema(ma.ModelSchema):

    class Meta:
        model = WorkspaceSettings

    @post_dump(pass_many=True)
    def unwrap_settings(self, data, many):

        if many:
            return [item['settings'] or {} for item in data]
        else:
            return data['settings'] or {}

Post a Comment for "Marshmallow Result Customization"