Я довольно новичок в питоне. У меня есть две модели SQLAlchemy следующим образом:
class listing(db.Model):
id = db.Integer(primary_key=True)
title = db.String()
location_id = db.Column(db.Integer, db.ForeignKey('location.id'))
location = db.relationship('Location', lazy='joined')
class location(db.Model):
id = db.Integer(primary_key=True)
title = db.String()
У меня есть два класса схемы Marshmallow для них:
class ListingSchema(Schema):
id = fields.Int()
title = fields.Str()
location_id = fields.Int()
class LocationSchema(Schema):
id = fields.Int()
title = fields.Str()
Я создал вложенный класс схемы, например:
class NestedSchema(Schema):
listing = fields.Nested(ListingSchema)
location fields.Nested(LocationSchema)
Я делаю запрос на соединение, например:
listing,location = db.session.query(Listing,Location)\
.join(Location, and_(Listing.location_id == Location.id))\
.filter(Listing.id == listing_id).first()
данные загружаются в объекты, которые я проверил. Как разобрать эту схему? я пытался
result,errors = nested_listing_Schema(listing,location)
Это дает ошибку: «Объект листинга не является итерируемым».
nested_listing_Schema
- person Moses Koledoye   schedule 04.09.2016