I am creating a Flask API using SQLAlchemy models. I do not want to define a circuit for each model that I have, I do not want to do this every time:
class EntrySchema(ma.ModelSchema):
class Meta:
model = Entry
I would like every model to have a circuit, so it can easily reset itself. Creating the default schema and installing Schema.Meta.model did not work:
class Entry(db.Model):
__tablename__ = 'entries'
id = db.Column(db.Integer, primary_key=True)
started_at = db.Column(db.DateTime)
ended_at = db.Column(db.DateTime)
description = db.Column(db.Text())
def __init__(self, data):
for key in data:
setattr(self, key, data[key])
self.Schema = Schema
self.Schema.Meta.model = self.__class__
def dump(self):
schema = self.Schema()
result = schema.dump(self)
return result
class Schema(ma.ModelSchema):
class Meta:
pass
Why is the general model replacement scheme different from the declared model?
source
share