class User(db.Model): __tablename__ = "user" id = db.Column(db.Integer, primary_key=True, autoincrement=True) category = db.Column(db.String(50), nullable=False) phone_number = db.Column(db.String(50)) email = db.Column(db.String(50), unique=True, nullable=False) address_id = db.Column(db.Integer, db.ForeignKey('address.id'), nullable=False) address = db.relationship("Address", backref=db.backref("user", uselist=False)) user_name = db.Column(db.String(50), unique=True, nullable=False) password_hash = db.Column(db.String(256), nullable=False) __mapper_args__ = { "polymorphic_identity": __tablename__, "polymorphic_on": category, } def __init__(self, user_name, password, category, phone_number, email): self.user_name = user_name self.password_hash = self.generate_hash(password) self.category = category self.phone_number = phone_number self.email = email @staticmethod def generate_hash(password): return pbkdf2_sha256.hash(password.encode("utf8")) @staticmethod def verify_hash(password, hashed_password): return pbkdf2_sha256.verify(password.encode("utf8"), hashed_password)
class OpenInternship(db.Model): __tablename__ = "open_internship" id = db.Column(db.Integer, primary_key=True, autoincrement=True) internship_code = db.Column(db.String(50), unique=True, nullable=False) company_id = db.Column(db.ForeignKey("company.id"), nullable=False) company = db.relationship("Company", backref=db.backref(__tablename__, uselist=False)) title = db.Column(db.String(250), nullable=False) description = db.Column(db.String(350), nullable=False) required_cgpa = db.Column(db.String(30), nullable=False) comments = db.Column(db.String(300)) start_date = db.Column(db.Date, nullable=False) end_date = db.Column(db.Date, nullable=False) def __init__(self, internship_code, company_id, title, description, required_cgpa, comments, start_date, end_date): self.internship_code = internship_code self.company_id = company_id self.title = title self.description = description self.required_cgpa = required_cgpa self.comments = comments self.start_date = start_date self.end_date = end_date
class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(120), unique=True) password = db.Column(db.String(128)) performances = db.relationship('Performance', backref='user') tokens = db.relationship('Token', backref='user') bookmarks = db.relationship('Station', secondary=user_bookmarks, backref='users') def __init__(self, email, password): self.email = email self.password = password
class Internship(db.Model): __tablename__ = "internship" id = db.Column(db.Integer, primary_key=True, autoincrement=True) internship_id = db.Column(db.ForeignKey("open_internship.id"), nullable=False) internship_details = db.relationship("OpenInternship", backref=db.backref(__tablename__, uselist=False)) university_id = db.Column(db.ForeignKey("university.id"), nullable=False) university = db.relationship("University", backref=db.backref(__tablename__, uselist=False)) student_id = db.Column(db.ForeignKey("student.id"), nullable=False) student = db.relationship("Student", backref=db.backref(__tablename__, uselist=False)) status = db.Column(db.String(30), nullable=False) def __init__(self, internship_id, university_id, student_id, status): self.internship_id = internship_id self.university_id = university_id self.student_id = student_id self.status = status
class University(User): __tablename__ = "university" id = db.Column(db.ForeignKey("user.id"), primary_key=True) name = db.Column(db.String(150), nullable=False) university_code = db.Column(db.String(50), unique=True, nullable=False) programs = db.relationship("Program", secondary="university_program", backref="universities") __mapper_args__ = {"polymorphic_identity": __tablename__} def __init__(self, user_name, password, phone_number, email, name, university_code): super().__init__(user_name, password, "university", phone_number, email) self.name = name self.university_code = university_code def __repr__(self): return ("University Name %s, " % (self.name))
class Student(User): __tablename__ = "student" id = db.Column(db.ForeignKey("user.id"), primary_key=True) first_name = db.Column(db.String(30), nullable=False) middle_name = db.Column(db.String(30), nullable=False) last_name = db.Column(db.String(30), nullable=False) registration_id = db.Column(db.String(50), unique=True, nullable=False) program_id = db.Column(db.Integer, db.ForeignKey('program.id'), nullable=False) program = db.relationship("Program", backref=db.backref(__tablename__, uselist=False)) __mapper_args__ = {"polymorphic_identity": __tablename__} def __init__(self, user_name, password, phone_number, email, first_name, middle_name, last_name, registration_id): super().__init__(user_name, password, "student", phone_number, email) self.first_name = first_name self.middle_name = middle_name self.last_name = last_name self.registration_id = registration_id