class User(db.Model): """ User Model for storing user related details """ __tablename__ = "user" id = db.Column(db.Integer, primary_key=True, autoincrement=True) public_id = db.Column(db.String(100), nullable=False, unique=True) password_hash = db.Column(db.String(100)) verification_code = db.Column(db.String(16), nullable=False, unique=True) name = db.Column(db.String(64), nullable=False) surname = db.Column(db.String(64), nullable=False) middle_name = db.Column(db.String(64), nullable=True, default=None) email = db.Column(db.String(120), unique=True) registered_on = db.Column(db.DateTime, nullable=False) admin = db.Column(db.Boolean, nullable=False, default=False) @property def password(self): raise AttributeError('password: write-only field') @password.setter def password(self, password): self.password_hash = flask_bcrypt.generate_password_hash( password).decode('utf-8') def check_password(self, password): return flask_bcrypt.check_password_hash(self.password_hash, password) def __repr__(self): return f'User {self.name} {self.surname}'
class CoursesAndGroups(db.Model): """ CoursesAndGroups Model for storing relations between study courses and study groups """ __tablename__ = "courses_and_groups" course_id = db.Column(db.Integer, db.ForeignKey('study_course.id'), primary_key=True) group_id = db.Column(db.Integer, db.ForeignKey('study_group.id'), primary_key=True)
class Student(USER_MODEL_CLASS): """ Student Model for storing student related details """ __tablename__ = "student" study_group_id = db.Column(db.Integer, db.ForeignKey('study_group.id'), nullable=False) entrance_year = db.Column(db.Integer, nullable=True, default=None) education_degree = db.Column(db.Enum(EducationDegree), nullable=False, default=EducationDegree.nan) education_form = db.Column(db.Enum(EducationForm), nullable=False, default=EducationForm.nan) education_basis = db.Column(db.Enum(EducationBasis), nullable=False, default=EducationBasis.nan) def __repr__(self): return f'Student {self.name} {self.surname}'
class StudyCourse(db.Model): """ StudyCourse Model for storing study course related details """ __tablename__ = "study_course" id = db.Column(db.Integer, primary_key=True, autoincrement=True) public_id = db.Column(db.String(100), nullable=False, unique=True) name = db.Column(db.String(64), nullable=False) description = db.Column(db.String(100), nullable=True) teachers = db.relationship('Teacher', secondary='courses_and_teachers', backref=db.backref('teachers', lazy='dynamic'), lazy='subquery') groups = db.relationship('StudyGroup', secondary='courses_and_groups', backref=db.backref('groups', lazy='dynamic'), lazy='subquery') def __repr__(self): return f'StudyCourse {self.name}'
class StudyGroup(db.Model): """ StudyGroup Model for storing groups of students related details """ __tablename__ = "study_group" id = db.Column(db.Integer, primary_key=True, autoincrement=True) public_id = db.Column(db.String(100), nullable=False, unique=True) n_course = db.Column(db.Integer, nullable=False, default=1) group_name = db.Column(db.String(64), nullable=False, unique=True) faculty_name = db.Column(db.String(64), nullable=False) students = db.relationship('student', backref='study_group', lazy='dynamic') courses = db.relationship('StudyCourses', secondary='courses_and_groups', backref=db.backref('courses', lazy='dynamic'), lazy='subquery') def __repr__(self): return f'StudyGroup {self.group_name}'
class MenuItem(db.Model): __tablename__ = 'menu_item' name = db.Column(db.String(80), nullable=False) id = db.Column(db.Integer, primary_key=True) description = db.Column(db.String(250)) price = db.Column(db.String(8)) course = db.Column(db.String(250)) restaurant_id = db.Column(db.Integer, db.ForeignKey('restaurant.id')) restaurant = db.relationship(Restaurant)
class Restaurant(db.Model): __tablename__ = 'restaurant' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(250), nullable=False)
class CoursesAndTeachers(db.Model): """ CoursesAndTeachers Model for storing relations between study courses and teachers """ __tablename__ = "courses_and_teachers" course_id = db.Column(db.Integer, db.ForeignKey('study_course.id'), primary_key=True) teacher_id = db.Column(db.Integer, db.ForeignKey('teacher.id'), primary_key=True)