-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
180 lines (154 loc) · 6.91 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_moment import Moment
import datetime
db = SQLAlchemy()
class Venue(db.Model):
__tablename__ = 'Venue'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
genres = db.Column(db.String(120))
city = db.Column(db.String(120))
state = db.Column(db.String(120))
address = db.Column(db.String(120))
phone = db.Column(db.String(120))
image_link = db.Column(db.String(500))
facebook_link = db.Column(db.String(120))
seeking_talent = db.Column(db.Boolean)
seeking_description = db.Column(db.String(500))
website = db.Column(db.String(120))
shows = db.relationship(
'Show', backref=db.backref('venue',single_parent=True, cascade='all, delete-orphan'))
@property
def properties(self):
return {'id': self.id,
'name': self.name,
'genres': self.genres.split(','),
'city': self.city,
'state': self.state,
'phone': self.phone,
'address': self.address,
'image_link': self.image_link,
'facebook_link': self.facebook_link,
'website': self.website,
'seeking_talent': self.seeking_talent,
'seeking_description': self.seeking_description,
}
@property
def properties_with_shows_details(self):
return {'id': self.id,
'name': self.name,
'city': self.city,
'genres': self.genres.split(','),
'state': self.state,
'phone': self.phone,
'address': self.address,
'image_link': self.image_link,
'facebook_link': self.facebook_link,
'seeking_talent': self.seeking_talent,
'seeking_description': self.seeking_description,
'website': self.website,
'upcoming_shows': [show.properties_with_artist_venue for show in Show.query.filter(
Show.start_time > datetime.datetime.now(),
Show.venue_id == self.id).all()],
'past_shows': [show.properties_with_artist_venue for show in Show.query.filter(
Show.start_time < datetime.datetime.now(),
Show.venue_id == self.id).all()],
'upcoming_shows_count': Show.query.filter(
Show.start_time > datetime.datetime.now(),
Show.venue_id == self.id).count(),
'past_shows_count': len(Show.query.filter(
Show.start_time < datetime.datetime.now(),
Show.venue_id == self.id).all())
}
@property
def filiter_venue_on_city_state(self):
return {'city': self.city,
'state': self.state,
'venues': [v.properties for v in Venue.query.filter(Venue.city == self.city,
Venue.state == self.state).all()]}
# 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)
city = db.Column(db.String(120))
state = db.Column(db.String(120))
address = db.Column(db.String(120))
phone = db.Column(db.String(120))
genres = db.Column(db.String(120))
image_link = db.Column(db.String(500))
facebook_link = db.Column(db.String(120))
website = db.Column(db.String(120))
seeking_venue = db.Column(db.Boolean)
seeking_description = db.Column(db.String(500))
shows = db.relationship(
'Show', backref=db.backref('artist', single_parent=True, cascade='all, delete-orphan'))
@property
def properties(self):
return {'id': self.id,
'name': self.name,
'city': self.city,
'state': self.state,
'phone': self.phone,
'genres': self.genres.split(','),
'image_link': self.image_link,
'facebook_link': self.facebook_link,
'seeking_venue': self.seeking_venue,
'seeking_description': self.seeking_description,
}
@property
def properties_with_shows_details(self):
return {'id': self.id,
'name': self.name,
'city': self.city,
'state': self.state,
'phone': self.phone,
'genres': self.genres.split(','),
'image_link': self.image_link,
'facebook_link': self.facebook_link,
'seeking_venue': self.seeking_venue,
'seeking_description': self.seeking_description,
'upcoming_shows': [show.properties_with_artist_venue for show in Show.query.filter(
Show.start_time > datetime.datetime.now(),
Show.artist_id == self.id).all()],
'past_shows': [show.properties_with_artist_venue for show in Show.query.filter(
Show.start_time < datetime.datetime.now(),
Show.artist_id == self.id).all()],
'upcoming_shows_count': len(Show.query.filter(
Show.start_time > datetime.datetime.now(),
Show.artist_id == self.id).all()),
'past_shows_count': len(Show.query.filter(
Show.start_time < datetime.datetime.now(),
Show.artist_id == self.id).all())
}
# TODO: implement any missing fields, as a database migration using Flask-Migrate
class Show(db.Model):
__tablename__ = 'Show'
id = db.Column(db.Integer, primary_key=True)
start_time = db.Column(db.DateTime())
venue_id = db.Column(db.Integer, db.ForeignKey(
'Venue.id'), nullable=False)
artist_id = db.Column(db.Integer, db.ForeignKey(
'Artist.id'), nullable=False)
@property
def properties(self):
return {'id': self.id,
'start_time': self.start_time.strftime("%m/%d/%Y, %H:%M:%S"),
'venue_id': self.venue_id,
'artist_id': self.artist_id,
'venue_name': self.venue.name,
'artist_name': self.artist.name ,
}
@property
def properties_with_artist_venue(self):
return {'id': self.id,
'start_time': self.start_time.strftime("%m/%d/%Y, %H:%M:%S"),
'venue_id': self.venue_id,
'artist_id': self.artist_id,
'venue_name': self.venue.name,
'artist_name': self.artist.name ,
'venue': [v.properties for v in Venue.query.filter(Venue.id == self.venue_id).all()][0],
'artist': [a.properties for a in Artist.query.filter(Artist.id == self.artist_id).all()][0]
}