-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
39 lines (28 loc) · 962 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
33
34
35
36
37
38
import os
from peewee import CharField, Field, ForeignKeyField, Model, TimeField
from playhouse.db_url import connect
from playhouse.postgres_ext import PostgresqlExtDatabase, ArrayField
database = connect(os.environ.get('DATABASE_URL'), autoconnect=False)
class BaseModel(Model):
class Meta:
database = database
class Buildings(BaseModel):
name = CharField()
class Meta:
table_name = 'buildings'
class Rooms(BaseModel):
building = ForeignKeyField(column_name='building_id', field='id', model=Buildings)
description = CharField()
number = CharField()
class Meta:
table_name = 'rooms'
class WeekdayField(Field):
field_type = 'weekday'
class Events(BaseModel):
days = ArrayField(WeekdayField)
end_time = TimeField()
name = CharField()
room = ForeignKeyField(column_name='room_id', field='id', model=Rooms)
start_time = TimeField()
class Meta:
table_name = 'events'