Varia library working group XPPL.
https://gitea.xpub.nl/XPUB/XPPL
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
from app import db
|
|
from marshmallow import Schema, fields, ValidationError, pre_load
|
|
|
|
class Book(db.Model):
|
|
__tablename__ = 'books'
|
|
id = db.Column(db.Integer, primary_key = True)
|
|
title = db.Column(db.String(255))
|
|
file = db.Column(db.String(255))
|
|
cover = db.Column(db.String(255))
|
|
fileformat = db.Column(db.String(255))
|
|
author = db.relationship('Author')
|
|
|
|
def __init__(self, title, file, cover, fileformat):
|
|
self.title = title
|
|
self.file = file
|
|
self.cover = cover
|
|
self.fileformat = fileformat
|
|
|
|
def __repr__(self):
|
|
return '<Title %r>' % self.title
|
|
|
|
def get_id(self):
|
|
return self.id
|
|
|
|
|
|
class Author(db.Model):
|
|
__tablename__ = 'authors'
|
|
id = db.Column(db.Integer(), primary_key=True)
|
|
user_id = db.Column(db.Integer(), db.ForeignKey('books.id'))
|
|
author_name = db.Column(db.String(50))
|
|
|
|
|
|
def __init__(self, author_name):
|
|
self.author_name = author_name
|
|
|
|
class BookSchema(Schema):
|
|
id = fields.Int(dump_only=True)
|
|
title = fields.Str()
|
|
author = fields.Str()
|
|
file = fields.Str()
|
|
cover = fields.Str()
|
|
fileformat = fields.Str()
|
|
|
|
def must_not_be_blank(data):
|
|
if not data:
|
|
raise ValidationError('Data not provided.')
|
|
|