-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
113 lines (97 loc) · 3.76 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
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
#----------------------------------------------------------------------------#
# Models.
#----------------------------------------------------------------------------#
db= SQLAlchemy()
class Venue(db.Model):
__tablename__ = 'Venue'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False)
genres = db.Column(db.ARRAY(db.String))
city = db.Column(db.String(120))
state = db.Column(db.String(120))
address = db.Column(db.String(120))
phone = db.Column(db.String(120))
website = db.Column(db.String(120))
seeking_talent = db.Column(db.Boolean, nullable=False, default = False)
seeking_description = db.Column(db.String(500))
image_link = db.Column(db.String(500))
facebook_link = db.Column(db.String(120))
shows = db.relationship('Show', backref='Venue', cascade="all, delete-orphan", lazy="dynamic")
def info(self):
return {
'id': self.id,
'name': self.name,
'genres': self.genres,
'address': self.address,
'city': self.city,
'state': self.state,
'phone': self.phone,
'website': self.website,
'facebook_link': self.facebook_link,
'seeking_talent': self.seeking_talent,
'seeking_description': self.seeking_description,
'image_link': self.image_link
}
# TODO: implement any missing fields, as a database migration using Flask-Migrate
class Artist(db.Model):
__tablename__ = 'Artist'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
genres = db.Column(db.ARRAY(db.String))
city = db.Column(db.String(120))
state = db.Column(db.String(120))
phone = db.Column(db.String(120))
website = db.Column(db.String(120))
seeking_venue = db.Column(db.Boolean, nullable=False, default = False)
seeking_description = db.Column(db.String(500))
image_link = db.Column(db.String(500))
facebook_link = db.Column(db.String(120))
shows = db.relationship('Show', backref='Artist', cascade="all, delete-orphan", lazy="dynamic")
def info(self):
return{
'id': self.id,
'name': self.name,
'genres': self.genres,
'city': self.city,
'state': self.state,
'phone': self.phone,
'website': self.website,
'facebook_link': self.facebook_link,
'seeking_venue': self.seeking_venue,
'seeking_description': self.seeking_description,
'image_link': self.image_link
}
# TODO: implement any missing fields, as a database migration using Flask-Migrate
# TODO Implement Show and Artist models, and complete all model relationships and properties, as a database migration.
class Show(db.Model):
__tablename__ = 'Show'
id = db.Column(db.Integer, primary_key=True)
venue_id = db.Column(db.Integer, db.ForeignKey('Venue.id'), nullable=False)
artist_id = db.Column(db.Integer, db.ForeignKey('Artist.id'), nullable=False)
start_time = db.Column(db.DateTime, nullable=False)
def info(self):
return{
'venue_id': self.venue_id,
'venue_name': self.Venue.name,
'artist_id': self.artist_id,
'artist_name': self.Artist.name,
'artist_image_link': self.Artist.image_link,
'start_time': self.start_time
}
def artist_info(self):
return{
'artist_id': self.artist_id,
'artist_name': self.Artist.name,
'artist_image_link': self.Artist.image_link,
'start_time': self.start_time
}
def venue_info(self):
return{
'venue_id': self.venue_id,
'venue_name': self.Venue.name,
'venue_image_link': self.Venue.image_link,
'start_time': self.start_time
}