class History(db.Model): id = db.Column(db.Integer, primary_key=True) search_query = db.Column(db.String(140)) timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow) username = db.Column(db.Integer, db.ForeignKey('user.username')) def __repr__(self): return '<Query : {}>'.format(self.search_query)
class Log(db.Model): __tablename__ = 'log' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), db.ForeignKey('user.username')) query = db.Column(db.String(140), nullable=False) #timestamp = db.Column(db.DateTime, primary_key=True) def __repr__(self): return '{}'.format(self.username)
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"User('{self.title}, {self.date_posted}')"
class Employee(UserMixin, db.Model): """ Create an Employee table """ # Ensures table will be named in plural and not in singular # as is the name of the model __tablename__ = 'employees' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(60), index=True, unique=True) username = db.Column(db.String(60), index=True, unique=True) first_name = db.Column(db.String(60), index=True) last_name = db.Column(db.String(60), index=True) password_hash = db.Column(db.String(128)) department_id = db.Column(db.Integer, db.ForeignKey('departments.id')) role_id = db.Column(db.Integer, db.ForeignKey('roles.id')) is_admin = db.Column(db.Boolean, default=False) @property def password(self): """ Prevent pasword from being accessed """ raise AttributeError('password is not a readable attribute.') @password.setter def password(self, password): """ Set password to a hashed password """ self.password_hash = generate_password_hash(password) def verify_password(self, password): """ Check if hashed password matches actual password """ return check_password_hash(self.password_hash, password) def __repr__(self): return '<Employee: {}>'.format(self.username)
class Post(db.Model): """ Posts Details Class""" id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(50)) content = db.Column(db.String(250)) member_id = db.Column(db.Integer, db.ForeignKey("member.id")) def __repr__(self): return f'Post id : {self.id}\nPost title : {self.title}\nPost content : {self.content}' def as_dict(self): return { "id": self.id, "title": self.title, "content": self.content, "member_id": self.member_id, "date": self.date, }