class Ticket(app_db.Model): """ status can be: open, assigned, reviewing, working, closed 1->N relationship with TicketMessages represented by the ticket back reference close_date should be assigned when the status is set to closed last_status_date should be assigned immediate with the initial status of open submitted_by and assigned_to both represent User.ID fields """ id = app_db.Column(app_db.Integer, primary_key=True) title = app_db.Column(app_db.String(75), nullable=False) summary = app_db.Column(app_db.Text, nullable=False) submitted_by = app_db.Column(app_db.Integer, app_db.ForeignKey('user.id'), nullable=False) assigned_to = app_db.Column(app_db.Integer, app_db.ForeignKey('user.id'), nullable=True) status = app_db.Column(app_db.String(10), nullable=False, default="open") create_date = app_db.Column(app_db.DateTime, nullable=False, default=datetime.utcnow) last_status_date = app_db.Column(app_db.DateTime, nullable=False, default=datetime.utcnow) close_date = app_db.Column(app_db.DateTime, nullable=True) messages = app_db.relationship('TicketMessage', backref=app_db.backref('ticket', lazy=True))
class User(app_db.Model, UserMixin): """ User account model """ id = app_db.Column(app_db.Integer, primary_key=True) email = app_db.Column(app_db.String(120), unique=True, nullable=False) first_name = app_db.Column(app_db.String(120), unique=True, nullable=False) last_name = app_db.Column(app_db.String(120), unique=True, nullable=False) password = app_db.Column(app_db.String(60), nullable=False) verified_email = app_db.Column(app_db.Boolean, nullable=False, default=False) create_date = app_db.Column(app_db.DateTime, nullable=False, default=datetime.utcnow) flag_admin = app_db.Column(app_db.Boolean, nullable=False, default=False) flag_cs = app_db.Column(app_db.Boolean, nullable=False, default=False) uac = app_db.relationship('UserAccessRoutes', secondary=uac, lazy='subquery', backref=app_db.backref('access', lazy=True)) def __repr__(self): return "<User('{}','{}','{}','{}')>".format(self.id, self.email, self.first_name, self.last_name)
class Review(app_db.Model): id = app_db.Column(app_db.Integer, primary_key=True) title = app_db.Column(app_db.String(120), nullable=False) content = app_db.Column(app_db.Text, nullable=False) user_id = app_db.Column(app_db.Integer, app_db.ForeignKey('user.id'), nullable=False) author = app_db.relationship('User', backref=app_db.backref('user', lazy=True)) approved = app_db.Column(app_db.Boolean, nullable=False, default=False) create_date = app_db.Column(app_db.DateTime, nullable=False, default=datetime.utcnow)
class ProductImage(app_db.Model): """ Represents a single stored image, names are hashed """ id = app_db.Column(app_db.Integer, primary_key=True) file_name = app_db.Column(app_db.String(120), unique=True, nullable=False) date_added = app_db.Column(app_db.DateTime, nullable=False, default=datetime.utcnow) def __repr__(self): return "ProductImage('{}', '{}', '{}')".format(self.id, self.file_name, self.date_added)
class Product(app_db.Model): id = app_db.Column(app_db.Integer, primary_key=True) title = app_db.Column(app_db.String(120), nullable=False) description = app_db.Column(app_db.Text, nullable=False, default="No Description") quantity = app_db.Column(app_db.Integer, nullable=False, default=0) price = app_db.Column(app_db.Float, nullable=False, default=0.0) expect_stock_quantity = app_db.Column(app_db.Integer, nullable=False, default=0) flag_out_of_stock = app_db.Column(app_db.Boolean, nullable=False, default=False) expect_restock_date = app_db.Column(app_db.DateTime, nullable=True) category_id = app_db.Column(app_db.Integer, app_db.ForeignKey('product_category.id'), nullable=False) category = app_db.relationship('ProductCategory', backref=app_db.backref('product', lazy=True)) def __repr__(self): return "<Product('{}', '{}', '{}')>".format(self.id, self.title, self.quantity)
class CustomerOrder(app_db.Model): """ status can be: open, reviewing, working, shipped, closed """ id = app_db.Column(app_db.Integer, primary_key=True) user_id = app_db.Column(app_db.Integer, app_db.ForeignKey('user.id'), nullable=False) create_date = app_db.Column(app_db.DateTime, nullable=False, default=datetime.utcnow) status = app_db.Column(app_db.String(10), nullable=False, default="open") last_status_date = app_db.Column(app_db.DateTime, nullable=False, default=datetime.utcnow) full_filled_date = app_db.Column(app_db.DateTime, nullable=True) shipped_date = app_db.Column(app_db.DateTime, nullable=True)
class ProductCategory(app_db.Model): id = app_db.Column(app_db.Integer, primary_key=True) description = app_db.Column(app_db.String(45), unique=True, nullable=False) def __repr__(self): return "<ProductCategory('{}', '{}')>".format(self.id, self.description)
class UserAccessRoutes(app_db.Model): id = app_db.Column(app_db.Integer, primary_key=True) route = app_db.Column(app_db.String(120), unique=True, nullable=False) def __repr__(self): return "<UserAccessRoutes('{}', '{}')>".format(self.id, self.route)