class LessonType(db.Model): id_ = db.Column('id', db.Integer, primary_key=True) name = db.Column(db.String(30), nullable=False) code = db.Column(db.String(1), nullable=False) lessons = db.relationship('Lesson', backref='type', lazy=True) def __repr__(self): return f"{self.name}"
class UserTimetable(db.Model): id_ = db.Column('id', db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) published = db.Column(db.Integer, default=0) slug = db.Column(db.String(30)) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) lessons = db.relationship('Lesson', secondary=user_timetable_lessons, backref=db.backref('user_timetable', lazy='joined'), lazy='dynamic')
class Subject(db.Model): id_ = db.Column('id', db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) code = db.Column(db.String(50), nullable=False) short_code = db.Column(db.String(20), nullable=False) credit_value = db.Column(db.Integer, nullable=False) rozsah = db.Column(db.String(30), nullable=True) external_id = db.Column(db.String(30), nullable=True) lessons = db.relationship('Lesson', backref='subject', lazy=True) def __repr__(self): return f"Subject(id:'{self.id_}', name:'{self.name}' )"
class Teacher(Entity): id_ = db.Column('id', db.Integer, primary_key=True) given_name = db.Column(db.String(50), nullable=True) family_name = db.Column(db.String(50), nullable=False) iniciala = db.Column(db.String(50), nullable=True) oddelenie = db.Column(db.String(), nullable=True) katedra = db.Column(db.String(), nullable=True) external_id = db.Column(db.String(), nullable=True) login = db.Column(db.String(), nullable=True) slug = db.Column(db.String(), nullable=True) lessons = db.relationship('Lesson', secondary=teacher_lessons, lazy='dynamic', backref=db.backref('teachers', lazy='joined', order_by="asc(Teacher.family_name)")) def __repr__(self): return f"Teacher(id:'{self.id_}', :'{self.given_name} {self.family_name}' )" @property def short_name(self): """E.g. for 'Andrej Blaho' return 'A. Blaho'""" if self.given_name is None or self.given_name.strip() == '': return self.family_name return self.given_name[0] + ". " + self.family_name @hybrid_property def fullname(self): return self.given_name + " " + self.family_name @hybrid_property # we need it in SQL queries def fullname_reversed(self): return self.family_name + " " + self.given_name
class Room(Entity): id_ = db.Column('id', db.Integer, primary_key=True) name = db.Column('name', db.String(30), nullable=False) room_type_id = db.Column(db.Integer, db.ForeignKey('room_type.id'), nullable=False) capacity = db.Column(db.Integer, nullable=False) lessons = db.relationship('Lesson', backref='room', lazy='dynamic') # 'lazy dynamic' allows us to work with lessons attribute like with query ( we can run order_by, etc) @property def prefix(self): # xMieRez is a special case: if 'xMieRez' in self.name: return "Ostatné" first_dash_position = self.name.find('-') if first_dash_position == -1: # name doesn't contain '-' return self.name return self.name[0 : first_dash_position] def __repr__(self): return "<Room %r>" % self.name
class StudentGroup(Entity): id_ = db.Column('id', db.Integer, primary_key=True) name = db.Column(db.String(30), nullable=False) lessons = db.relationship('Lesson', secondary=student_group_lessons, lazy='dynamic')
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) login = db.Column(db.String(50), unique=True) timetables = db.relationship('UserTimetable', backref='owner', lazy='dynamic')
class RoomType(db.Model): id_ = db.Column('id', db.Integer, primary_key=True) name = db.Column(db.String(30), nullable=False) code = db.Column(db.String(1), nullable=False)