okay we can / do have 2 separate instances of objects referring to either the children books (of a book with subbooks) or a parent ref if the book is a sub book of the parent book. Unused for now, but I think this means I could ditch my own raw sql, then we could also remove the ordering in the sql join, and use datatables sorting based on {{parent_ref.book_id}}.{{book.parent_ref.sub_book_num}}
This commit is contained in:
12
main.py
12
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 "<id: {}, author: {}, title: {}, year_published: {}, rating: {}, condition: {}, owned: {}, covertype: {}, notes: {}, blurb: {}, created: {}, modified: {}, publisher: {}>".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 )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user