class Category(db.Model): """ Table: Category of the Event""" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False, unique=True) events = db.relationship("Event", cascade="delete", back_populates="category")
class Organizer(db.Model): """ Table: Organizer of the Event""" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64), nullable=True) email = db.Column(db.String(100), nullable=False, unique=True) password = db.Column(db.String(50), nullable=False) events = db.relationship("Event", cascade="delete", back_populates="organizer")
class Venue(db.Model): """ Table: Venue of the Event""" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) url = db.Column(db.String(50), nullable=True) city_id = db.Column(db.Integer, db.ForeignKey("city.id", ondelete="CASCADE"), nullable=False) events = db.relationship("Event", cascade="delete", back_populates="venue") city = db.relationship("City", back_populates="venues")
class Event(db.Model): """ Table: Event """ id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) description = db.Column(db.String(250), nullable=True) startTime = db.Column(db.DateTime, nullable=False) venue_id = db.Column(db.Integer, db.ForeignKey("venue.id", ondelete="CASCADE"), nullable=False) organizer_id = db.Column(db.Integer, db.ForeignKey("organizer.id", ondelete="CASCADE"), nullable=False) category_id = db.Column(db.Integer, db.ForeignKey("category.id", ondelete="CASCADE"), nullable=False) url = db.Column(db.String(250), nullable=True, default="") venue = db.relationship("Venue", back_populates="events") organizer = db.relationship("Organizer", back_populates="events") category = db.relationship("Category", back_populates="events") def set_url(self): self.url = self.name + "-at-" + self.venue.name + "-" + self.startTime.strftime( "%Y%m%d%H%M")
class City(db.Model): """ Table: City of the Venue""" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False, unique=True) venues = db.relationship("Venue", cascade="delete", back_populates="city")