forked from Azure-Samples/msdocs-flask-postgresql-sample-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
32 lines (25 loc) · 927 Bytes
/
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
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String
from sqlalchemy.orm import validates
from app import db
class Restaurant(db.Model):
__tablename__ = 'restaurant'
id = Column(Integer, primary_key=True)
name = Column(String(50))
street_address = Column(String(50))
description = Column(String(250))
def __str__(self):
return self.name
class Review(db.Model):
__tablename__ = 'review'
id = Column(Integer, primary_key=True)
restaurant = Column(Integer, ForeignKey('restaurant.id', ondelete="CASCADE"))
user_name = Column(String(30))
rating = Column(Integer)
review_text = Column(String(500))
review_date = Column(DateTime)
@validates('rating')
def validate_rating(self, key, value):
assert value is None or (1 <= value <= 5)
return value
def __str__(self):
return f"{self.user_name}: {self.review_date:%x}"