changed publisher link over to a 1-to-many, removed book_publisher_link table, etc. fully works in show books, edit book for publisher now
This commit is contained in:
14
main.py
14
main.py
@@ -16,7 +16,7 @@ ma = Marshmallow(app)
|
|||||||
Bootstrap(app)
|
Bootstrap(app)
|
||||||
|
|
||||||
from author import Author, AuthorForm, AuthorSchema, GetAuthors
|
from author import Author, AuthorForm, AuthorSchema, GetAuthors
|
||||||
from publisher import Publisher, PublisherForm, PublisherSchema, GetPublishers
|
from publisher import Publisher, PublisherForm, PublisherSchema, GetPublisherById
|
||||||
from genre import Genre, GenreForm, GenreSchema, GetGenres
|
from genre import Genre, GenreForm, GenreSchema, GetGenres
|
||||||
from condition import Condition, ConditionForm, ConditionSchema, GetConditionById
|
from condition import Condition, ConditionForm, ConditionSchema, GetConditionById
|
||||||
from covertype import Covertype, CovertypeForm, CovertypeSchema, GetCovertypeById
|
from covertype import Covertype, CovertypeForm, CovertypeSchema, GetCovertypeById
|
||||||
@@ -31,11 +31,6 @@ book_author_link = db.Table('book_author_link', db.Model.metadata,
|
|||||||
db.Column('author_id', db.Integer, db.ForeignKey('author.id'))
|
db.Column('author_id', db.Integer, db.ForeignKey('author.id'))
|
||||||
)
|
)
|
||||||
|
|
||||||
book_publisher_link = db.Table('book_publisher_link', db.Model.metadata,
|
|
||||||
db.Column('book_id', db.Integer, db.ForeignKey('book.id')),
|
|
||||||
db.Column('publisher_id', db.Integer, db.ForeignKey('publisher.id'))
|
|
||||||
)
|
|
||||||
|
|
||||||
book_genre_link = db.Table('book_genre_link', db.Model.metadata,
|
book_genre_link = db.Table('book_genre_link', db.Model.metadata,
|
||||||
db.Column('book_id', db.Integer, db.ForeignKey('book.id')),
|
db.Column('book_id', db.Integer, db.ForeignKey('book.id')),
|
||||||
db.Column('genre_id', db.Integer, db.ForeignKey('genre.id'))
|
db.Column('genre_id', db.Integer, db.ForeignKey('genre.id'))
|
||||||
@@ -75,7 +70,7 @@ class Book(db.Model):
|
|||||||
id = db.Column(db.Integer, unique=True, nullable=False, primary_key=True)
|
id = db.Column(db.Integer, unique=True, nullable=False, primary_key=True)
|
||||||
title = db.Column(db.String(100), unique=True, nullable=False)
|
title = db.Column(db.String(100), unique=True, nullable=False)
|
||||||
author = db.relationship('Author', secondary=book_author_link)
|
author = db.relationship('Author', secondary=book_author_link)
|
||||||
publisher = db.relationship('Publisher', secondary=book_publisher_link)
|
publisher = db.Column(db.Integer, db.ForeignKey('publisher.id'))
|
||||||
genre = db.relationship('Genre', secondary=book_genre_link )
|
genre = db.relationship('Genre', secondary=book_genre_link )
|
||||||
loan = db.relationship('Loan', secondary=Book_Loan_Link.__table__);
|
loan = db.relationship('Loan', secondary=Book_Loan_Link.__table__);
|
||||||
series = db.relationship('Series', secondary=Book_Series_Link.__table__);
|
series = db.relationship('Series', secondary=Book_Series_Link.__table__);
|
||||||
@@ -154,7 +149,6 @@ class Book_Series_LinkSchema(ma.SQLAlchemyAutoSchema):
|
|||||||
# so I just hacked a list of keys in book.html
|
# so I just hacked a list of keys in book.html
|
||||||
class BookSchema(ma.SQLAlchemyAutoSchema):
|
class BookSchema(ma.SQLAlchemyAutoSchema):
|
||||||
author = ma.Nested(AuthorSchema, many=True)
|
author = ma.Nested(AuthorSchema, many=True)
|
||||||
publisher = ma.Nested(PublisherSchema, many=True)
|
|
||||||
genre = ma.Nested(GenreSchema, many=True)
|
genre = ma.Nested(GenreSchema, many=True)
|
||||||
loan = ma.Nested(LoanSchema, many=True)
|
loan = ma.Nested(LoanSchema, many=True)
|
||||||
series = ma.Nested(SeriesSchema, many=True)
|
series = ma.Nested(SeriesSchema, many=True)
|
||||||
@@ -182,11 +176,11 @@ class BookForm(FlaskForm):
|
|||||||
app.jinja_env.globals['GetCovertypeById'] = GetCovertypeById
|
app.jinja_env.globals['GetCovertypeById'] = GetCovertypeById
|
||||||
app.jinja_env.globals['GetOwnedById'] = GetOwnedById
|
app.jinja_env.globals['GetOwnedById'] = GetOwnedById
|
||||||
app.jinja_env.globals['GetConditionById'] = GetConditionById
|
app.jinja_env.globals['GetConditionById'] = GetConditionById
|
||||||
|
app.jinja_env.globals['GetPublisherById'] = GetPublisherById
|
||||||
app.jinja_env.globals['SeriesBookNum'] = SeriesBookNum
|
app.jinja_env.globals['SeriesBookNum'] = SeriesBookNum
|
||||||
|
|
||||||
### DDP: do I need many=True on Author as books have many authors? (or in BookSchema declaration above?)
|
### DDP: do I need many=True on Author as books have many authors? (or in BookSchema declaration above?)
|
||||||
book_schema = BookSchema()
|
book_schema = BookSchema()
|
||||||
books_schema = BookSchema(many=True)
|
|
||||||
|
|
||||||
################################# helper functions ###################################
|
################################# helper functions ###################################
|
||||||
def GetBookIdFromSeriesByBookNum( series_id, book_num ):
|
def GetBookIdFromSeriesByBookNum( series_id, book_num ):
|
||||||
@@ -341,6 +335,7 @@ def book(id):
|
|||||||
book.owned = request.form['owned']
|
book.owned = request.form['owned']
|
||||||
book.covertype = request.form['covertype']
|
book.covertype = request.form['covertype']
|
||||||
book.condition = request.form['condition']
|
book.condition = request.form['condition']
|
||||||
|
book.publisher = request.form['publisher']
|
||||||
book.year_published = request.form['year_published']
|
book.year_published = request.form['year_published']
|
||||||
book.rating = request.form['rating']
|
book.rating = request.form['rating']
|
||||||
book.notes = request.form['notes']
|
book.notes = request.form['notes']
|
||||||
@@ -369,7 +364,6 @@ def book(id):
|
|||||||
message="Err... Failed to update Book (id={})".format(id)
|
message="Err... Failed to update Book (id={})".format(id)
|
||||||
else:
|
else:
|
||||||
book_form=BookForm(obj=book)
|
book_form=BookForm(obj=book)
|
||||||
book_form.publisher.default = book.publisher[0].id
|
|
||||||
|
|
||||||
author_list = GetAuthors()
|
author_list = GetAuthors()
|
||||||
genre_list = GetGenres()
|
genre_list = GetGenres()
|
||||||
|
|||||||
@@ -68,3 +68,6 @@ def publisher(id):
|
|||||||
publisher_form = PublisherForm(request.values, obj=publisher)
|
publisher_form = PublisherForm(request.values, obj=publisher)
|
||||||
message=""
|
message=""
|
||||||
return render_template("edit_id_name.html", publisher=publisher, alert=alert, message=message, form=publisher_form, page_title='Edit Publisher')
|
return render_template("edit_id_name.html", publisher=publisher, alert=alert, message=message, form=publisher_form, page_title='Edit Publisher')
|
||||||
|
|
||||||
|
def GetPublisherById(id):
|
||||||
|
return Publisher.query.get(id).name
|
||||||
|
|||||||
Reference in New Issue
Block a user