|
|
@ -1,6 +1,11 @@
|
|
|
|
from app import db
|
|
|
|
from app import db
|
|
|
|
from marshmallow import Schema, fields, ValidationError, pre_load
|
|
|
|
from marshmallow import Schema, fields, ValidationError, pre_load
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
authors = db.Table('books_authors',
|
|
|
|
|
|
|
|
db.Column('book_id', db.Integer, db.ForeignKey('books.id'), primary_key=True),
|
|
|
|
|
|
|
|
db.Column('author_id', db.Integer, db.ForeignKey('authors.id'), primary_key=True)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class Book(db.Model):
|
|
|
|
class Book(db.Model):
|
|
|
|
__tablename__ = 'books'
|
|
|
|
__tablename__ = 'books'
|
|
|
|
id = db.Column(db.Integer, primary_key = True)
|
|
|
|
id = db.Column(db.Integer, primary_key = True)
|
|
|
@ -8,9 +13,10 @@ class Book(db.Model):
|
|
|
|
file = db.Column(db.String(255))
|
|
|
|
file = db.Column(db.String(255))
|
|
|
|
cover = db.Column(db.String(255))
|
|
|
|
cover = db.Column(db.String(255))
|
|
|
|
fileformat = db.Column(db.String(255))
|
|
|
|
fileformat = db.Column(db.String(255))
|
|
|
|
author = db.relationship('Author')
|
|
|
|
|
|
|
|
tag = db.Column(db.String(255))
|
|
|
|
tag = db.Column(db.String(255))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
authors = db.relationship('Author', secondary=authors, lazy='subquery',
|
|
|
|
|
|
|
|
backref=db.backref('books', lazy=True))
|
|
|
|
def __init__(self, title, file, cover, fileformat, tag):
|
|
|
|
def __init__(self, title, file, cover, fileformat, tag):
|
|
|
|
|
|
|
|
|
|
|
|
self.title = title
|
|
|
|
self.title = title
|
|
|
@ -30,7 +36,7 @@ class Book(db.Model):
|
|
|
|
class Author(db.Model):
|
|
|
|
class Author(db.Model):
|
|
|
|
__tablename__ = 'authors'
|
|
|
|
__tablename__ = 'authors'
|
|
|
|
id = db.Column(db.Integer(), primary_key=True)
|
|
|
|
id = db.Column(db.Integer(), primary_key=True)
|
|
|
|
user_id = db.Column(db.Integer(), db.ForeignKey('books.id'))
|
|
|
|
book_id = db.Column(db.Integer(), db.ForeignKey('books.id'))
|
|
|
|
author_name = db.Column(db.String(50))
|
|
|
|
author_name = db.Column(db.String(50))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|