I have a sqlalchemy database association between Type and Language and am trying to get marshmallow to pull a specific column string from Language but it only wants to give me the object of Language converted to a string.
Here is my TypeSchema
class TypeSchema(ma.SQLAlchemySchema):
class Meta:
model = Type
ordered = True
#If I put ma.String().language it gives me an error
languages = ma.List(ma.String(), dump_only=True, many=True)
This produces this json output
{
"languages": [
"<api.models.Language object at 0x000001C15E60A320>"
]
}
This is my desired output
{
"languages": [
"en", "sp", "de"
]
}
Here is my models.py
class Language(Updateable, db.Model):
__tablename__ = 'language'
id = sqla.Column(sqla.Integer, primary_key=True)
language = sqla.Column(sqla.String(2), nullable=False)
type_id = sqla.Column(sqla.Integer, sqla.ForeignKey(Type.id), index=True)
type = sqla_orm.relationship('Type', back_populates='languages')
class Type(Updateable, db.Model):
__tablename__ = 'type'
id = sqla.Column(sqla.Integer, primary_key=True)
languages = sqla_orm.relationship('Language', back_populates='type')