xppl/app/models.py
2018-05-23 11:16:25 +02:00

32 lines
800 B
Python
Executable File

from app import db
from marshmallow import Schema, fields, ValidationError, pre_load
class Book(db.Model):
id = db.Column(db.Integer, primary_key = True)
title = db.Column(db.String(255))
author = db.Column(db.String(255))
file = db.Column(db.String(255))
tag = db.Column(db.String(255))
def __init__(self, title, author, file, tag):
self.title = title
self.author = author
self.file = file
self.tag = tag
def __repr__(self):
return '<Title %r>' % self.title
class BookSchema(Schema):
id = fields.Int(dump_only=True)
title = fields.Str()
author = fields.Str()
file = fields.Str()
tag = fields.Str()
def must_not_be_blank(data):
if not data:
raise ValidationError('You forgot to write stuff.')