Repository navigation
Expand file tree
/
Copy pathmodel.py
More file actions
83 lines (55 loc) · 2.37 KB
/
Copy pathmodel.py
File metadata and controls
83 lines (55 loc) · 2.37 KB
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
""" Model for my local sound app"""
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class User(db.Model):
""" A user for the app """
__tablename__ = "users"
user_id = db.Column(db.Integer,
primary_key = True,
autoincrement = True)
u_name = db.Column(db.String(30), unique = True)
u_password = db.Column(db.String(30))
email = db.Column(db.String)
location_id = db.Column(db.Integer, db.ForeignKey('locations.location_id'))
site_theme = db.Column(db.String, nullable = True)
def __repr__(self):
return f"{self.u_name} is in {self.location_id} \n"
class Artist(db.Model):
""" The arts and location I am scrapping from a csv"""
__tablename__ = "artists"
artist_id = db.Column(db.Integer,
primary_key = True,
autoincrement = True)
artist_name = db.Column(db.String, unique = True, nullable = False)
artist_password = db.Column(db.String)
seed_status = db.Column(db.String, nullable=False)
location_id = db.Column(db.Integer, db.ForeignKey('locations.location_id'))
artist_URI = db.Column(db.String, unique = True, nullable=True)
link_1 = db.Column(db.String, unique = True, nullable = True)
link_2 = db.Column(db.String, unique = True, nullable=True)
def __repr__(self):
return f"{self.artist_name} is rockin in {self.location_id}\n"
class Location(db.Model):
""" Location is everything and nothing in the digital age"""
__tablename__ = "locations"
location_id = db.Column(db.Integer,
primary_key = True,
autoincrement = True)
city = db.Column(db.String)
state = db.Column(db.String)
artists = db.relationship('Artist', backref='location')
users = db.relationship('User', backref='location')
def __repr__(self):
return f"Location {self.city}, {self.state} \n"
def connect_to_db(flask_app, db_uri="postgresql:///localsound", echo = True):
flask_app.config["SQLALCHEMY_DATABASE_URI"] = db_uri
flask_app.config["SQLALCHEMY_ECHO"] = echo
flask_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.app = flask_app
db.init_app(flask_app)
print("Connected to the Data Base")
if __name__ == "__main__":
from server import app
connect_to_db(app)
# db.drop_all()
# db.create_all()