-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
25 lines (20 loc) · 707 Bytes
/
models.py
File metadata and controls
25 lines (20 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from datetime import datetime
from config import db, ma
from sqlalchemy import true
# Define db model to allow working with SQL Alchemy
class Person(db.Model):
__table_name__ = "person"
person_id = db.Column(db.Integer, primary_key=True)
lname = db.Column(db.String(100), index=True)
fname = db.Column(db.String(100))
timestamp = db.Column(
db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
)
# Marshmallow Schema
class PersonSchema(ma.SQLAlchemyAutoSchema):
class Meta:
# Set SQLAlchemy model into model
model = Person
# Set SQLAlchemy db session into marshmallow
sqla_session = db.session
load_instance = true