Answer the question
In order to leave comments, you need to log in
How to achieve automatic generation of Shema models using Marshmallow and SQLAlchemyAutoSchema?
It seems to be acting according to the documentation here
. There is a model and a diagram:
class TypeMaterial(db.Model):
__tablename__ = 'types_material'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20), unique=True)
description = db.Column(db.String(255))
def __repr__(self):
return f'<ICC Profile: {self.name}>'
# Исплользую SQLAlchemyAutoSchema для авто-генерации схемы
class TypeMaterialSchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = TypeMaterial
load_instance = True
@api.route('/')
@login_required
def index():
items = TypeMaterial.query().all()
result = TypeMaterialSchema.dump(items)
pprint(result)
File "E:\MyPyProjects\flask\app\api\blueprint.py", line 45, in index
result = TypeMaterialSchema.dump(items)
TypeError: dump() missing 1 required positional argument: 'obj'
Answer the question
In order to leave comments, you need to log in
Found a solution
items = TypeMaterial.query.all()
items_schema = TypeMaterialSchema(many=True)
results = items_schema.dump(items)
print(results)
return jsonify(results)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question