0

I get the following JSON as an input:

{
        "832.547.13 Temperatur 1": "1337",
        "832.547.23 Temperatur 2": "2323"
}

But I cant use these JSON-Datafields in my db.Model, so I make this:

class DataModel(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    Temperatur_1 = db.Column("832.547.13 Temperatur 1", db.String, index=True, quote=True)
    Temperatur_2 = db.Column("832.547.23 Temperatur 2", db.String, index=True, quote=True)

Question: Is there a way to dump and load data with flask marshmallow with the names like 832.547.13 Temperatur 1?

If I want to write a new row at the moment, I have to pass my JSON this way:

{
        "Temperatur_1": "123123123",
        "Temperatur_2": "123123123"
}
meai2312
  • 167
  • 4
  • 12

1 Answers1

0

I managed it this way:

class DataSchema(ma.ModelSchema):
    Temperatur_1 = fields.String(required=True, data_key='832.547.13 Temperatur 1')
    Temperatur_2 = fields.String(required=True, data_key='832.547.23 Temperatur 2')

    class Meta:
        model = DataModel
meai2312
  • 167
  • 4
  • 12