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

9
README
View File

@@ -19,6 +19,11 @@ python3 main.py
### TODO:
- fix up lame book linkages to tabels that are so not 3nf, *_LST tables, etc.
- ORM:
- saving a book with the ORM is probably the last oddity... probably time to try it (in a sense, the book edit page is the only time we change things, maybe we mess with that book-query as its too slow, and for book edit, if we don't allow editing items like author/publisher, then may only need to set the objects we want to change... I'm sort of curious can you save a book table based on id, without saging its author table, seems that should be okay, but how do I save both, just create 2 objects and do it, but what if the ORM has auto-connected bunches of stuff, how do I update the connected stuff.... MAYBE, I need to get say loan or something first, then try all this? (make a pop-up for stuff like loans, but what about series or sub-book editing????)
- consider getting rest of Book class connected, e.g. series, loan, etc.
- see if we can break this out of main.py -- can't recall what was circular about this, but at least the wtf bits seem to be able to be moved out, so why not do that
- get main.html to be some sort of include so that other htmls, can be clicked on / use back button, reload, etc. and it all works, but the whoel thing feels like a discrete app
### MAYBE, I should make this a self-contained docker instance, then its a copy of the DB and anything I break will be fixable
### next step is to rename genre_lst to genre, and maybe do similar to all _lst tables... then add genre.py in and get it to work

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 )