okay, condition* now works, menu to call them works, just testing it out though, so also a BookForm started but unused at present. Finally, tweaked pagination size to 20 now that navbar takes up so much space, also made pagination choices match

This commit is contained in:
2020-11-16 00:03:28 +11:00
parent ff749dfdf5
commit 58695629dc
4 changed files with 128 additions and 5 deletions

26
main.py
View File

@@ -4,6 +4,7 @@ from flask import request
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
from flask_bootstrap import Bootstrap
from wtforms import SubmitField, StringField, HiddenField, SelectField, validators, Form
app = Flask(__name__)
### what is this value? I gather I should chagne it?
@@ -18,6 +19,7 @@ Bootstrap(app)
from author import Author, AuthorForm, AuthorSchema
from publisher import Publisher, PublisherForm, PublisherSchema
from genre import Genre, GenreForm, GenreSchema
from condition import Condition, ConditionForm, ConditionSchema
####################################### CLASSES / DB model #######################################
book_author_link = db.Table('book_author_link', db.Model.metadata,
@@ -47,19 +49,19 @@ class Book_Sub_Book_Link(db.Model):
class Book(db.Model):
id = db.Column(db.Integer, unique=True, nullable=False, primary_key=True)
title = db.Column(db.String(100), unique=True, nullable=False)
author = db.relationship('Author', secondary=book_author_link)
publisher = db.relationship('Publisher', secondary=book_publisher_link)
genre = db.relationship('Genre', secondary=book_genre_link )
year_published = db.Column(db.Integer)
rating = db.Column(db.String(20))
condition = db.Column(db.String(20))
owned = db.Column(db.String(20))
covertype = db.Column(db.String(20))
condition = db.Column(db.String(20))
rating = db.Column(db.String(20))
notes = db.Column(db.Text)
blurb = db.Column(db.Text)
created = db.Column(db.Date)
modified = db.Column(db.Date)
author = db.relationship('Author', secondary=book_author_link)
publisher = db.relationship('Publisher', secondary=book_publisher_link)
genre = db.relationship('Genre', secondary=book_genre_link )
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" )
@@ -69,6 +71,9 @@ class Book(db.Model):
class Book_Sub_Book_LinkSchema(ma.SQLAlchemyAutoSchema):
class Meta: model = Book_Sub_Book_Link
# Note not ordering this in the code below as, I can't work out how to use
# jinja2 to iterate over orderedDict - seems it doesnt support it?
# so I just hacked a list of keys in book.html
class BookSchema(ma.SQLAlchemyAutoSchema):
author = ma.Nested(AuthorSchema, many=True)
publisher = ma.Nested(PublisherSchema, many=True)
@@ -77,6 +82,17 @@ class BookSchema(ma.SQLAlchemyAutoSchema):
child_ref = ma.Nested(Book_Sub_Book_LinkSchema, many=True)
class Meta: model = Book
#
# To be completed
#
class BookForm(Form):
# I think I'll have to skip setting default on create, and using jquery to
# change it when I create the from? (or maybe I could use a default=set_me
# in the line below, then when I set create set_me = book.condition before
# bf=BookForm()
condition = SelectField( 'condition', choices=[(c.id, c.name) for c in Condition.query.order_by('id')] )
### DDP: do I need many=True on Author as books have many authors? (or in BookSchema declaration above?)
book_schema = BookSchema()
books_schema = BookSchema(many=True)