-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
65 lines (50 loc) · 2.49 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
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.dialects.postgresql import ARRAY
db = SQLAlchemy()
#----------------------------------------------------------------------------#
# Models.
#----------------------------------------------------------------------------#
class Venue(db.Model):
__tablename__ = 'Venue'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False)
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.ARRAY(db.String), nullable=False) # To store genres as a comma-separated string
facebook_link = db.Column(db.String(120), nullable=True)
image_link = db.Column(db.String(500), nullable=True)
website_link = db.Column(db.String(500), nullable=True)
seeking_talent = db.Column(db.Boolean, default=False) # Boolean to indicate if seeking talent
seeking_description = db.Column(db.String(500), nullable=True)
# Relationship with Show model
shows = db.relationship('Show', backref='venue', lazy=True)
def num_upcoming_shows(self):
# Implement the logic to count upcoming shows
return Show.query.filter(Show.venue_id == self.id).count()
def __repr__(self):
return f'<Venue {self.name}, City: {self.city}, State: {self.state}>'
class Artist(db.Model):
__tablename__ = 'Artist'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False)
city = db.Column(db.String(120))
state = db.Column(db.String(120))
phone = db.Column(db.String(120))
genres = db.Column(db.ARRAY(db.String), nullable=False)
image_link = db.Column(db.String(500))
facebook_link = db.Column(db.String(120))
website_link = db.Column(db.String(120))
seeking_venue = db.Column(db.Boolean, default=False)
seeking_description = db.Column(db.String(500), nullable=True)
# Relationship with Show model
shows = db.relationship('Show', backref='artist', lazy=True)
class Show(db.Model):
__tablename__ = 'Show'
id = db.Column(db.Integer, primary_key=True)
artist_id = db.Column(db.Integer, db.ForeignKey('Artist.id'), nullable=False)
venue_id = db.Column(db.Integer, db.ForeignKey('Venue.id'), nullable=False)
show_time = db.Column(db.DateTime, nullable=False)
def __repr__(self):
return f'<Show {self.id}: {self.artist.name} at {self.venue.name} on {self.show_time.strftime("%A %B %d, %Y at %I:%M %p")}>'