-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
144 lines (117 loc) · 4.81 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from uuid import uuid4
from datetime import datetime
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import UserMixin, LoginManager
from flask_marshmallow import Marshmallow
import secrets
login_manager = LoginManager()
ma = Marshmallow()
db = SQLAlchemy()
# @login_manager.user_loader
# def load_user(user_id):
# return User.query.get(user_id)
class Users(db.Model):
id = db.Column(db.String, primary_key=True)
location_id = db.Column(db.String, nullable=True, default="")
saved_1_id = db.Column(db.String, nullable=True, default="")
saved_2_id = db.Column(db.String, nullable=True, default="")
saved_3_id = db.Column(db.String, nullable=True, default="")
def __init__(self, id, location_id, saved_1_id='', saved_2_id='', saved_3_id=''):
self.id = id
self.location_id = location_id
self.saved_1_id = saved_1_id
self.saved_2_id = saved_2_id
self.saved_3_id = saved_3_id
def __repr__(self):
return f"User {self.id} has been added to the database"
class UserLocation(db.Model):
user_location_id = db.Column(db.String, primary_key=True)
user_id = db.Column(db.String, nullable=False)
city = db.Column(db.String, nullable=False)
state = db.Column(db.String, nullable=False)
grid_id = db.Column(db.String, nullable=False)
grid_x = db.Column(db.Float, nullable=False)
grid_y = db.Column(db.Float, nullable=False)
def __init__(self, user_id, city, state, grid_id, grid_x, grid_y):
self.user_location_id = self.set_id()
self.user_id = user_id
self.city = city
self.state = state
self.grid_id = grid_id
self.grid_x = grid_x
self.grid_y = grid_y
def set_id(self):
return str(uuid4())
def __repr__(self):
return f"User Location has been added to the database"
class SavedOneLocation(db.Model):
saved_1_location_id = db.Column(db.String, primary_key=True)
user_id = db.Column(db.String, nullable=False)
city = db.Column(db.String, nullable=False)
state = db.Column(db.String, nullable=False)
grid_id = db.Column(db.String, nullable=False)
grid_x = db.Column(db.Float, nullable=False)
grid_y = db.Column(db.Float, nullable=False)
def __init__(self, user_id, city, state, grid_id, grid_x, grid_y):
self.saved_1_location_id = self.set_id()
self.user_id = user_id
self.city = city
self.state = state
self.grid_id = grid_id
self.grid_x = grid_x
self.grid_y = grid_y
def set_id(self):
return str(uuid4())
def __repr__(self):
return f"Saved 1 Location has been added to the database"
class SavedTwoLocation(db.Model):
saved_2_location_id = db.Column(db.String, primary_key=True)
user_id = db.Column(db.String, nullable=False)
city = db.Column(db.String, nullable=False)
state = db.Column(db.String, nullable=False)
grid_id = db.Column(db.String, nullable=False)
grid_x = db.Column(db.Float, nullable=False)
grid_y = db.Column(db.Float, nullable=False)
def __init__(self, user_id, city, state, grid_id, grid_x, grid_y):
self.saved_2_location_id = self.set_id()
self.user_id = user_id
self.city = city
self.state = state
self.grid_id = grid_id
self.grid_x = grid_x
self.grid_y = grid_y
def set_id(self):
return str(uuid4())
def __repr__(self):
return f"Saved 2 Location has been added to the database"
class SavedThreeLocation(db.Model):
saved_3_location_id = db.Column(db.String, primary_key=True)
user_id = db.Column(db.String, nullable=False)
city = db.Column(db.String, nullable=False)
state = db.Column(db.String, nullable=False)
grid_id = db.Column(db.String, nullable=False)
grid_x = db.Column(db.Float, nullable=False)
grid_y = db.Column(db.Float, nullable=False)
def __init__(self, user_id, city, state, grid_id, grid_x, grid_y):
self.saved_3_location_id = self.set_id()
self.user_id = user_id
self.city = city
self.state = state
self.grid_id = grid_id
self.grid_x = grid_x
self.grid_y = grid_y
def set_id(self):
return str(uuid4())
def __repr__(self):
return f"Saved 3 Location has been added to the database"
class UserSchema(ma.Schema):
class Meta:
fields = ['id', 'location_id', 'saved_1_id', 'saved_2_id', 'saved_3_id']
class LocationSchema(ma.Schema):
class Meta:
fields = ['city', 'state', 'grid_id', 'grid_x', 'grid_y']
user_schema = UserSchema()
users_schema = UserSchema(many=True)
location_schema = LocationSchema()