При запросе на сервер выдает ответ:
{
"id": 16,
"title": "3rd movie",
"genre": "Genres.FANTASY",
"director": 1
}
Нужно чтобы по id директора возвращалась информация о нем
{
"id": 16,
"title": "3rd movie",
"genre": "Genres.FANTASY",
"director": "name surname"
}
models.py
class Film(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(255), nullable=False)
genre = db.Column(db.Enum(Genres), default=None)
director = db.Column(db.Integer, db.ForeignKey('director.id'), default=None)
def __repr__(self):
return self.title
def save(self):
db.session.add(self)
db.session.commit()
def delete(self):
db.session.delete(self)
db.session.commit()
@classmethod
def get_by_name(cls, name):
return cls.query.get_or_404(name)
class Director(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), nullable=False)
surname = db.Column(db.String(255), nullable=False)
film = db.relationship('Film')
def __repr__(self):
return self.name + ' ' + self.surname
def save(self):
db.session.add(self)
db.session.commit()
def delete(self):
db.session.delete(self)
db.session.commit()
схема
schema = movie.model(
'Film', {
'id': fields.Integer(),
'title': fields.String(),
'genre': fields.String(enums=['ACTION', 'COMEDY', 'DRAMA', 'HORROR', 'FANTASY']),
'director': fields.Integer()
}
)