Answer the question
In order to leave comments, you need to log in
How to make nested fields in marshmallow?
I have a very simple model and diagram:
class Exam(db.Model):
id = db.Column(db.Integer, primary_key=True)
subject = db.Column(db.String(255))
teacher = db.Column(db.String(255))
room = db.Column(db.Integer)
def __init__(self, subject, teacher, room):
self.subject = subject
self.teacher = teacher
self.room = room
class ExamSchema(ma.Schema):
class Meta:
fields = ("id", "subject", "teacher", "room")
{
"id": 1,
"subject": "Math",
"teacher": "John Doe",
"room": 405
},
{
"id": 2,
"subject": "Geometry",
"teacher": "John Doe",
"room": 406
}
teacher: "John Doe",
exams: {[
id, subject, room ...
]}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question