class Product(db.Model): __tablename__ = 'products' id = db.Column(db.Integer, primary_key=True) product_name = db.Column(db.String(100), nullable=False) author_name = db.Column(db.String(100), nullable=False) product_description = db.Column(db.Text(500), nullable=False) price = db.Column(db.Float, nullable=False) category_id = db.Column(db.Integer, db.ForeignKey("categories.id"), nullable=False) created_at = db.Column(db.DateTime, default=db.func.now()) status = db.Column(db.String(50), default="IN STOCK") #image = db.Column(db.String(100), nullable=False) def __repr__(self): return '<Product %r>' % self.product_name def serialize(self): return { "id": self.id, "name": self.product_name, "author_name": self.author_name, "product_description": self.product_description, "price": self.price, "category": self.category.category_name, "created at": str(self.created_at), "status": self.status, #"image": self.image }
class Comment(db.Model): """A comment""" __tablename__ = "comments" comment_id = db.Column(db.Integer, autoincrement=True, primary_key=True) comment_text = db.Column(db.Text()) star_rating = db.Column(db.Integer) timestamp = db.Column( db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow ) users = db.relationship("User", secondary="users_comments", back_populates="comments", cascade="all, delete") activities = db.relationship("Activity", secondary="activities_comments",back_populates="comments", cascade="all, delete") activities_comments= db.relationship("ActivityComment", back_populates="comments", cascade="all, delete") users_comments= db.relationship("UserComment", back_populates="comments", cascade="all, delete") def __repr__(self): return f'<Comment comment_id={self.comment_id} name={self.star_rating}>'
class User(UserMixin, db.Model): """Main User class for the DB""" id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(64), unique=True) username = db.Column(db.String(24), unique=True) pwd = db.Column(db.Text()) about_me = db.Column(db.Text()) date = db.Column(Date, default=datetime.datetime.now) # Constructor def __init__(self, username, email, pwd, about_me=None): self.username = username self.email = email self.pwd = pwd self.about_me = about_me
class Events(db.Model): __tablename__ = 'data_events' id = db.Column(db.Integer, primary_key=True) date = db.Column(db.Date, nullable=False) time = db.Column(db.Time) title = db.Column(db.Text(255), nullable=False) event_content = db.Column(db.Text(), nullable=False) created_on = db.Column(db.DateTime(), default=datetime.utcnow) updated_on = db.Column(db.DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow) user_email = db.Column(db.Integer(), db.ForeignKey('users.email')) def __init__(self, date, time, title, event_content): self.date = date self.time = time self.title = title self.event_content = event_content
class MenuItem(db.Model): id = db.Column(db.Integer, db.Sequence('seq_reg_id', start=1, increment=1), unique=True) name = db.Column(db.String(50), nullable=False, primary_key=True) category = db.Column(db.String(50)) price = db.Column(db.Integer, nullable=False) description = db.Column(db.Text()) type = db.Column(db.String(20)) restaurantId = db.Column(db.Integer, db.ForeignKey("restaurant.id"), primary_key=True)
class Rating(db.Model): id = db.Column(db.Integer, primary_key=True) restaurantId = db.Column(db.Integer, db.ForeignKey("restaurant.id")) userId = db.Column(db.Integer, db.ForeignKey("user.id")) price = db.Column(db.Integer, nullable=False) food = db.Column(db.Integer, db.CheckConstraint('food<6'), db.CheckConstraint('food>0'), nullable=False) mood = db.Column(db.Integer, db.CheckConstraint('mood<6'), db.CheckConstraint('mood>0'), nullable=False) staff = db.Column(db.Integer, db.CheckConstraint('staff<6'), db.CheckConstraint('staff>0'), nullable=False) comment = db.Column(db.Text()) date = db.Column(db.Date)
class Account(db.Model): __tablename__ = 'account' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True) password = db.Column(db.String(80), nullable=False) settings = db.Column(db.Text(), nullable=False) timetables = db.relationship('TimeTable', backref='account', lazy=True) running = db.relationship('Running', backref='account', lazy=True) timestamp = db.Column(db.TIMESTAMP, nullable=False) paid = db.Column(db.Boolean, default=False) started = db.Column(db.Boolean, default=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) credit = db.Column(db.Integer, default=0) subscription = db.Column(db.String(80), unique=True) paid = db.Column(db.Boolean, default=False) def __repr__(self): return '<Account %r>' % self.username
class Appointment(db.Model): """docstring for Appointment""" __tablename__ = "Appointment" id_appointment = db.Column(db.Integer, nullable=False, primary_key=True) date = db.Column(db.DateTime(), nullable=False) description = db.Column(db.Text(length=None), nullable=False, ) weight = db.Column(db.Float(), nullable=True) height = db.Column(db.Float(), nullable=True) temperature = db.Column(db.Float(), nullable=True) heart_rate = db.Column(db.Float(), nullable=True) done = db.Column(db.Boolean(), nullable=False) username = db.Column(db.String(30),db.ForeignKey( 'User.username'),nullable=False ) id_patient = db.Column(db.String(10),db.ForeignKey( 'Patient.id_patient'),nullable=False ) def __repr__(self): return '{},{},{},{},{},{},{}, {}, {}, {}|'.format(self.id_appointment, self.date, self.description, self.weight, self.height, self.temperature, self.heart_rate, self.done, self.username, self.id_patient)
class Paper(db.Model): __tablename__ = 'paper' id = db.Column(db.Integer, primary_key=True) status = db.Column(db.String(120), nullable=False) title = db.Column(db.String(120), nullable=False) abstract = db.Column(db.Text(500), nullable=False) # relationships authors = db.relationship('User', secondary=authors, lazy='subquery', backref=db.backref('papers', lazy=True)) reviewers = db.relationship("Score", back_populates="paper") scores = db.relationship("Score", back_populates="paper") def has_reviewer(self, user): for reviewer in self.reviewers: if reviewer.reviewer.id == user.id: return True return False def __repr__(self): return '<Paper %r>' % self.title