-
Notifications
You must be signed in to change notification settings - Fork 3
/
models.py
91 lines (77 loc) · 2.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
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 flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from run import db
driverPicks = db.Table('driverPicks',
db.Column('driver_id', db.Integer, db.ForeignKey('driver.id')),
db.Column('passenger_id', db.Integer, db.ForeignKey('passenger.id'))
)
passengerPicks = db.Table('passengerPicks',
db.Column('driver_id', db.Integer, db.ForeignKey('driver.id')),
db.Column('passenger_id', db.Integer, db.ForeignKey('passenger.id'))
)
class Driver(db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String)
alias = db.Column(db.String)
editURL = db.Column(db.String)
validated = db.Column(db.Boolean)
oLat = db.Column(db.Numeric)
oLon = db.Column(db.Numeric)
dLat = db.Column(db.Numeric)
dLon = db.Column(db.Numeric)
date = db.Column(db.String)
picks = db.relationship('Passenger', secondary='driverPicks', backref=db.backref('pickedBy',lazy='dynamic'))
def __init__(self, email, alias, oLat, oLon, dLat, dLon, date, url):
self.email = email
self.alias = alias
self.validated = False
self.oLat = oLat
self.oLon = oLon
self.dLat = dLat
self.dLon = dLon
self.date = date
self.editURL = url
def __repr__(self):
return '<User %r>' % self.email
def pick(self, passenger):
self.picks.append(passenger)
return self
def unpick(self, passenger):
self.picks.remove(passenger)
return self
def validate(self):
self.validated = True
return self
class Passenger(db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String)
alias = db.Column(db.String)
editURL = db.Column(db.String)
validated = db.Column(db.Boolean)
oLat = db.Column(db.Numeric)
oLon = db.Column(db.Numeric)
dLat = db.Column(db.Numeric)
dLon = db.Column(db.Numeric)
date = db.Column(db.String)
picks = db.relationship('Driver', secondary='passengerPicks', backref=db.backref('pickedBy',lazy='dynamic'))
def __init__(self, email, alias, oLat, oLon, dLat, dLon, date, url):
self.email = email
self.alias = alias
self.validated = False
self.oLat = oLat
self.oLon = oLon
self.dLat = dLat
self.dLon = dLon
self.date = date
self.editURL = url
def __repr__(self):
return '<User %r>' % self.email
def pick(self, driver):
self.picks.append(driver)
return self
def unpick(self, driver):
self.picks.remove(driver)
return self
def validate(self):
self.validated = True
return self