remove publisher* from main.py, for now remove ORM complexities for sub_books in books, just do it by hand and cleaned up a few debugs, comments

This commit is contained in:
2020-11-15 12:22:41 +11:00
parent 29f8189c97
commit c675786852
2 changed files with 16 additions and 21 deletions

28
main.py
View File

@@ -65,13 +65,6 @@ class Book(db.Model):
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 )
#$class Publisher(db.Model):
# id = db.Column(db.Integer, unique=True, nullable=False, primary_key=True)
# name = db.Column(db.String(50), unique=False, nullable=False)
#
# def __repr__(self):
# return "<id: {}, name: {}>".format(self.id, self.name)
class Genre_Lst(db.Model):
__tablename__ = "genre_lst"
id = db.Column(db.Integer, unique=True, nullable=False, primary_key=True)
@@ -80,9 +73,6 @@ class Genre_Lst(db.Model):
def __repr__(self):
return "<id: {}, genre: {}>".format(self.id, self.genre)
#class PublisherSchema(ma.SQLAlchemyAutoSchema):
# class Meta: model = Publisher
class Genre_LstSchema(ma.SQLAlchemyAutoSchema):
class Meta: model = Genre_Lst
@@ -104,17 +94,17 @@ books_schema = BookSchema(many=True)
####################################### ROUTES #######################################
@app.route("/books", methods=["GET"])
def books():
books = Book.query.outerjoin(Book_Sub_Book_Link, Book.id==Book_Sub_Book_Link.book_id).order_by(Book.id, Book_Sub_Book_Link.sub_book_num).all()
books = Book.query.all()
# ignore ORM, its too slow. Just select sub_book data and hand add it to
# the books object, and use it in jinja2 to indent/order the books/sub books
subs = db.engine.execute ( "select * from book_sub_book_link" )
for row in subs:
index = next((i for i, item in enumerate(books) if item.id == row.sub_book_id), -1)
books[index].parent_id = row.book_id
books[index].sub_book_num = row.sub_book_num
books_s = books_schema.dump(books)
return render_template("books.html", books=books, tst=books_s)
# return render_template("books.html", books=books_s)
return render_template("books.html", books=books)
@app.route("/book/<id>", methods=["GET"])
def book(id):
@@ -123,7 +113,7 @@ def book(id):
######
###
### okay, this manual hacking of sub_book is currently going to be needed, because in the jinja2 I want to list the book, and more than just the id numhber of the sub_book, I want the details... (sub_book_schema needs a book relationship BUT, dependencies mean I can't define a book schema inside sub_book schema, and I am definitely not sure how to join it anyway... for another time.
### okay, this manual hacking of sub_book is currently going to be needed, because in the jinja2 I want to list the book, and more than just the id number of the sub_book, I want the details... (sub_book_schema needs a book relationship BUT, dependencies mean I can't define a book schema inside sub_book schema, and I am definitely not sure how to join it anyway... for another time.
###
#####
# force sub books for jinja2 to be able to use
@@ -140,10 +130,10 @@ def book(id):
book_s['sub_book'] = sub_book
print( "parent book details:" )
print( book.parent_ref )
print( "child book details:" )
print( book.child_ref )
# print( "parent book details:" )
# print( book.parent_ref )
# print( "child book details:" )
# print( book.child_ref )
return render_template("book.html", books=book_s, subs=sub_book )