class Searches(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) search_query = db.Column(db.String(8000), nullable=False) def __repr__(self): return f"Search('{self.id}', '{self.user_id}','{self.search_query}')"
class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) password = db.Column(db.String(40), nullable=False) last_login = db.Column(db.DateTime, nullable=False, default=datetime.now()) def __repr__(self): return f"User('{self.username}', '{self.password}')"
class Role(db.Model): """Class to model a User's Role Args: db (SQLAlchemy): The Database we want to use """ id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(50), unique=True)
class Grades(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) subject = db.Column(db.String(50), nullable=False) grade = db.Column(db.String(2), nullable=False) def __repr__(self): return f"Grades('{self.user_id}', '{self.subject}','{self.grade}')"
class Logs(db.Model): id = db.Column(db.Integer, primary_key=True) activity = db.Column(db.String(20), nullable=False) message = db.Column(db.Text, nullable=False) timestamp = db.Column(db.String(50), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Logs('{self.activity}', '{self.message}', '{self.timestamp}')"
class Posts(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) subject = db.Column(db.String(50), nullable=False) title = db.Column(db.String(50), nullable=False) content = db.Column(db.String(8000), nullable=False) def __repr__(self): return f"Posts('{self.id}', '{self.user_id}','{self.content}','{self.subject}','{self.title}')"
class User(UserMixin, db.Model): """Class to model a User Args: UserMixin (UserMixin): This provides default implementations for the methods that Flask-Login expects user objects to have db (SQLAlchemy): The Database we want to use """ id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) # Relationships role_id = db.Column(db.Integer(), db.ForeignKey('role.id')) def __repr__(self): """To represent a User with a string Returns: string: return a string representing a user """ return '<User {}>'.format(self.username) def set_password(self, password): """Set the password of the User Args: password (string): password set by the User """ self.password_hash = generate_password_hash(password) def check_password(self, password): """Check if the password indicates by the User is the same as in the database Args: password (string): password set by the User Returns: boolean: True if the password matched, False otherwise. """ return check_password_hash(self.password_hash, password) def set_default_role(self): """Set the default role for a User """ self.role_id = 2
class Activites(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) post_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) type = db.Column(db.String(40), nullable=False) timestamp = db.Column(db.DateTime, nullable=False, default=datetime.now()) content = db.Column(db.String(8000), nullable=False) def __repr__(self): return f"Activities('{self.id}', '{self.user_id}','{self.post_id}','{self.type}','{self.timestamp}','{self.content}')"
class User_Id_Store(db.Model): store = db.Column(db.Integer, primary_key=True)