-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
44 lines (38 loc) · 1.43 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
from app import db
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
from sqlalchemy.orm import declarative_base, validates
# declarative base class
Base = declarative_base()
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)
class School(db.Model):
__tablename__ = 'school'
school_name = Column(String, primary_key=True)
school_registration = Column(String)
school_address = Column(String)
primary_contact_name = Column(String)
primary_contact_email = Column(String)
primary_contact_position = Column(String)
secondary_contact_name = Column(String)
secondary_contact_email = Column(String)
secondary_contact_position = Column(String)
@validates('rating')
def validate_rating(self, key, value):
assert value is None or (1 <= value <= 5)
return value
def __str__(self):
return self.restaurant.name + " (" + self.review_date.strftime("%x") +")"