diff --git a/README b/README index bf06eba..b55675c 100644 --- a/README +++ b/README @@ -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 diff --git a/main.py b/main.py index add620e..50323de 100644 --- a/main.py +++ b/main.py @@ -65,13 +65,6 @@ class Book(db.Model): 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 ) -#$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 "".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 "".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/", 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 )