-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
46 lines (36 loc) · 1.14 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
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import orm
from sqlalchemy import (
Column,
Integer,
String,
Date,
Enum,
Float,
ForeignKey)
Base = declarative_base()
class Account(Base):
__tablename__ = 'accounts'
id = Column(Integer, primary_key=True)
name = Column(String)
locations = orm.relationship('Location', backref='account')
users = orm.relationship('User', backref='account')
class Location(Base):
__tablename__ = 'locations'
id = Column(Integer, primary_key=True)
account_id = Column(Integer, ForeignKey('accounts.id'))
name = Column(String)
address = Column(String)
features = orm.relationship('Feature', backref='location')
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
account_id = Column(Integer, ForeignKey('accounts.id'))
name = Column(String)
class Feature(Base):
__tablename__ = 'features'
id = Column(Integer, primary_key=True)
location_id = Column(Integer, ForeignKey('locations.id'))
name = Column(Enum('high', 'low'))
date = Column(Date)
value = Column(Float)