-
Notifications
You must be signed in to change notification settings - Fork 0
/
Models.py
91 lines (68 loc) · 2.36 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from peewee import *
import datetime
database = MySQLDatabase(None)
class BaseModel(Model):
class Meta():
database = database
class Member(BaseModel):
username = CharField()
email = CharField()
password = CharField()
date_added = DateTimeField(default=datetime.datetime.now)
class Stop(BaseModel):
abbr = CharField(unique=True)
name = CharField()
updated = DateTimeField(default=datetime.datetime.now)
def to_display_dict(self):
return {
'id': self.id,
'name': self.name,
'abbr': self.abbr
}
class Route(BaseModel):
# Number has to be char; routes have letters
route = CharField()
description = CharField()
providerid = CharField()
updated = DateTimeField(default=datetime.datetime.now)
def available_directions(self):
directions = Direction.select().dicts()\
.join(RouteDirectionAssociation)\
.where(RouteDirectionAssociation.route == self)
return directions
def to_display_dict(self):
return {
'id': self.id,
'description': self.description,
'number': self.route
}
class Direction(BaseModel):
value = IntegerField()
text = CharField()
def to_display_dict(self):
return {
'id': self.id,
'name': self.text,
'value': self.value
}
class RouteStopAssociation(BaseModel):
route = ForeignKeyField(Route, related_name='r_route')
stop = ForeignKeyField(Stop, related_name='r_stop')
class RouteDirectionAssociation(BaseModel):
route = ForeignKeyField(Route, related_name='d_route')
direction = ForeignKeyField(Direction, related_name='d_direction')
class HotStop(BaseModel):
member = ForeignKeyField(Member, related_name='hotstops')
route = ForeignKeyField(Route, related_name='hs_route')
direction = ForeignKeyField(Direction, related_name='hs_direction')
stop = ForeignKeyField(Stop, related_name='hs_stop')
added_on = DateTimeField()
updated = DateTimeField(default=datetime.datetime.now)
dashboard = BooleanField(default=True)
def to_display_dict(self):
return {
'direction': self.direction.to_display_dict(),
'id': self.id,
'route': self.route.to_display_dict(),
'stop': self.stop.to_display_dict(),
}