-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
53 lines (37 loc) · 1.47 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship
from flask_marshmallow import Marshmallow
db = SQLAlchemy()
ma = Marshmallow()
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
firebase_uid = db.Column(db.String(255), unique=True,
nullable=False)
first_name = db.Column(db.String(50), nullable=False)
last_name = db.Column(db.String(50), nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
date_created = db.Column(
db.DateTime, nullable=False, default=datetime.utcnow)
beers = relationship("Beer", backref="user_owner")
def __repr__(self):
return f"User('{self.first_name}', '{self.last_name}', '{self.email}')"
class Beer(db.Model):
__tablename__ = 'beers'
id = db.Column(db.Integer, primary_key=True)
brewery = db.Column(db.String(50))
name = db.Column(db.String(100), nullable=False)
abv = db.Column(db.Float)
style = db.Column(db.String(75))
comments = db.Column(db.String(500))
rating = db.Column(db.Float)
user_id = db.Column(db.Integer, ForeignKey('users.id'))
owner = relationship("User")
class BeerSchema(ma.Schema):
class Meta:
fields = ['id', 'brewery', 'name', 'abv',
'style', 'comments', 'rating']
beer_schema = BeerSchema()
beers_schema = BeerSchema(many=True)