class Publisher(db.Model): id = db.Column(db.Integer, primary_key=True) publisher_name = db.Column(db.String(20), nullable=False) def __init__(self, publisher_name): self.publisher_name = publisher_name def __repr__(self): return f"Publisher('{self.publisher_name}')"
class Ticket(db.Model): id = db.Column(db.Integer, primary_key=True) tenant_email = db.Column(db.String(120), db.ForeignKey("tenant.email")) room_id = db.Column(db.Integer, nullable=False) build_id = db.Column(db.Integer, nullable=False) mtype = db.Column(db.String(40), nullable=False) submitdate = db.Column(db.Date, nullable=False) resolvedate = db.Column(db.Date) description = db.Column(db.String(720), nullable=False) def __init__(self, email, room_id, build_id, mtype, description, submitdate, resolvedate): self.tenant_email=email self.room_id=room_id self.build_id=build_id self.mtype=mtype self.description=description self.submitdate=submitdate self.resolvedate=resolvedate
class Customer(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) balance = db.Column(db.Numeric(4, 2)) orders = db.relationship("Purchase", cascade="all, delete-orphan") returns = db.relationship("Return", cascade="all, delete-orphan") __table_args__ = (CheckConstraint(balance >= 0, name='check_bar_positive'), {}) def __init__(self, username, email, password, balance): self.username = username self.email = email self.password = password self.balance = balance def __repr__(self): return f"Customer('{self.username}', '{self.email}', '{self.balance}')"
class Game(db.Model): id = db.Column(db.Integer, primary_key=True) game_name = db.Column(db.String(50), nullable=False) genre = db.Column(db.String(50), nullable=False) release_date = db.Column(db.Date, nullable=False) price = db.Column(db.Numeric(4, 2), nullable=False) publisher_id = db.Column(db.Integer, db.ForeignKey('publisher.id')) order_details = db.relationship("Odetails", cascade="all, delete-orphan") runs = db.relationship("Run", cascade="all, delete-orphan") def __init__(self, game_name, genre, release_date, price, publisher_id): self.game_name = game_name self.genre = genre self.release_date = release_date self.price = price self.publisher_id = publisher_id def __repr__(self): return f"Game('{self.game_name}', '{self.genre}', '{self.release_date}', '{self.price}', '{self.publisher_id}')"
class Tenant(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) access = db.Column(db.Integer, nullable=False) def __init__(self, username, email, password, access=ACCESS['tenant']): self.name = username self.email = email self.password = password self.access = access def is_admin(self): return self.access == ACCESS['admin'] def allowed(self, access_level): return self.access >= access_level def __repr__(self): return f"Customer('{self.name}', '{self.email}')"
class Platform(db.Model): id = db.Column(db.Integer, primary_key=True) platform_name = db.Column(db.String(50), nullable=False) release_date = db.Column(db.Date, nullable=False) price = db.Column(db.Numeric(4, 2), nullable=False) runs = db.relationship("Run", cascade="all, delete-orphan") def __init__(self, platform_name, release_date, price): self.platform_name = platform_name self.release_date = release_date self.price = price def __repr__(self): return f"Game('{self.platform_name}', '{self.release_date}', '{self.price}')"