diff --git a/main.py b/main.py index a999fba..d0b2863 100644 --- a/main.py +++ b/main.py @@ -52,7 +52,8 @@ class Book(db.Model): author = db.relationship('Author', secondary=book_author_link) publisher = db.relationship('Publisher', secondary=book_publisher_link) genre = db.relationship('Genre_Lst', secondary=book_genre_link ) - subs = db.relationship('Book_Sub_Book_Link', secondary=Book_Sub_Book_Link.__table__, primaryjoin="Book.id==Book_Sub_Book_Link.sub_book_id", secondaryjoin="Book.id==Book_Sub_Book_Link.book_id" ) + parent_ref = db.relationship('Book_Sub_Book_Link', secondary=Book_Sub_Book_Link.__table__, primaryjoin="Book.id==Book_Sub_Book_Link.sub_book_id", secondaryjoin="Book.id==Book_Sub_Book_Link.book_id" ) + child_ref = db.relationship('Book_Sub_Book_Link', secondary=Book_Sub_Book_Link.__table__, primaryjoin="Book.id==Book_Sub_Book_Link.book_id", secondaryjoin="Book.id==Book_Sub_Book_Link.sub_book_id" ) def __repr__(self): return "".format(self.id, self.author, self.title, self.year_published, self.rating, self.condition, self.owned, self.covertype, self.notes, self.blurb, self.created, self.modified, self.publisher ) @@ -109,7 +110,8 @@ class BookSchema(ma.SQLAlchemyAutoSchema): author = ma.Nested(AuthorSchema, many=True) publisher = ma.Nested(PublisherSchema, many=True) genre = ma.Nested(Genre_LstSchema, many=True) - subs = ma.Nested(Book_Sub_Book_LinkSchema, many=True) + parent_ref = ma.Nested(Book_Sub_Book_LinkSchema, many=True) + child_ref = ma.Nested(Book_Sub_Book_LinkSchema, many=True) class Meta: model = Book include_relationships = True @@ -157,8 +159,10 @@ def book(id): book_s['sub_book'] = sub_book - print( book.genre ) - print( book.subs ) + print( "parent book details:" ) + print( book.parent_ref ) + print( "child book details:" ) + print( book.child_ref ) return render_template("books.html", books=book_s, subs=sub_book )