-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
42 lines (28 loc) · 1.32 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
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship, Session
from database import Base
class Building(Base):
__tablename__ = 'buildings'
id = Column(Integer, primary_key=True, index=True)
name = Column(String(120), unique=True, index=True)
location = Column(String(120))
is_pv_installed = Column(Boolean, default=False)
username = Column(String, ForeignKey('users.username'))
measurements = relationship("Measurement", back_populates="building")
owner = relationship("User", back_populates="buildings")
class Measurement(Base):
__tablename__ = 'measurements'
starttime = Column(String(120), primary_key=True, index=True)
endtime = Column(String(120))
energy = Column(Integer)
unit = Column(String(2))
building_name = Column(String, ForeignKey('buildings.name'), nullable=False)
building = relationship("Building", back_populates="measurements", lazy=True)
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True, index=True)
email = Column(String(120), unique=True, index=True)
username = Column(String(120), unique=True, index=True)
password = Column(String(128))
is_active = Column(Boolean, default=True)
buildings = relationship("Building", back_populates="owner")