In my Rest application I want to return json
like JSONAPI
format, but I need to create Schema class for it and create every field again that are already there in my model
. So instead of creating every field in schema class can I not take it from DB Model
..
below is my model class
class Author(db.Model):
id = db.Column(db.Integer)
name = db.Column(db.String(255))
I am defining Schema like below.
class AuthorSchema(Schema):
id = fields.Str(dump_only=True)
name = fields.Str()
metadata = fields.Meta()
class Meta:
type_ = 'people'
strict = True
So here, id
and name
I have defined it twice. so is there any option in marshmallow-jsonapi
to assign model name in schema class so it can take all fields from model
Note: I am using marshmallow-jsonapi
for it, I have tried marshmallow-sqlalchemy
, it has that option but it not return json
in JSONAPI
format