Ejemplo n.º 1
0
class Venue(PkModelMixin, db.Model):
    __tablename__ = "venues"

    name = db.Column(db.String)
    address = db.Column(db.String(120))

    genres = db.relationship(Genres, secondary=genre_venue_assoc)

    seeking_talent = db.Column(db.Boolean, nullable=False, default=False)
    seeking_description = db.Column(db.String, nullable=True)

    # MANY venues has ONE city
    city_id = db.Column(db.Integer, db.ForeignKey("cities.id"), nullable=False)
    city = db.relationship(City, back_populates="venues")

    # ONE venues has ONE contact info
    contact_info_id = db.Column(db.Integer,
                                db.ForeignKey("contact_info.id"),
                                nullable=False,
                                unique=True)
    contact_info = db.relationship(ContactInfo,
                                   uselist=False,
                                   cascade="all, delete-orphan",
                                   single_parent=True)

    # ONE venue has MANY shows
    shows = db.relationship(Show,
                            back_populates="venue",
                            cascade="all, delete-orphan")

    def __repr__(self):
        return f"<Venue name:{self.name}>"
Ejemplo n.º 2
0
class City(PkModelMixin, db.Model):
    __tablename__ = "cities"
    name = db.Column(db.String)

    # MANY city have ONE state
    state_id = db.Column(db.Integer, db.ForeignKey("states.id"))
    state = db.relationship("State", back_populates="cities", lazy="joined")

    # ONE city has MANY venues
    venues = db.relationship("Venue")

    # ONE city has MANY artists
    artists = db.relationship("Artist")

    def __repr__(self):
        return f"<City name:{self.name} state:{self.state}>"
Ejemplo n.º 3
0
class Show(PkModelMixin, db.Model):
    __tablename__ = "shows"

    start_time = db.Column(db.DateTime, nullable=False)

    artist_id = db.Column(db.Integer,
                          db.ForeignKey("artists.id"),
                          nullable=False)
    artist = db.relationship("Artist", back_populates="shows")

    venue_id = db.Column(db.Integer,
                         db.ForeignKey("venues.id"),
                         nullable=False)
    venue = db.relationship("Venue", back_populates="shows")

    def __repr__(self):
        return f"<Show id:{self.id} start_time:{self.start_time}>"
Ejemplo n.º 4
0
class State(PkModelMixin, db.Model):
    __tablename__ = "states"
    name = db.Column(db.String)

    # ONE state has MANY cities
    cities = db.relationship("City")

    def __repr__(self):
        return f"<State name:{self.name}>"