-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
22 lines (18 loc) · 802 Bytes
/
models.py
File metadata and controls
22 lines (18 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import datetime
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Author(db.Model):
__tablename__ = 'authors'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), nullable=False)
age = db.Column(db.Integer, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.datetime.now())
books = db.relationship("Book")
class Book(db.Model):
__tablename__ = 'books'
id = db.Column(db.Integer, primary_key=True)
isbn = db.Column(db.String(255), nullable=False)
name = db.Column(db.String(255), nullable=False)
cant_pages = db.Column(db.Integer, nullable=False, default=0)
created_at = db.Column(db.DateTime, default=datetime.datetime.now())
author_id = db.Column(db.Integer, db.ForeignKey('authors.id'))