class Duty(db.Model): __tablename__ = 'duties' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), index=True, unique=True, nullable=False) desc = db.Column(db.Text) update_user = db.Column(db.Integer) create_time = db.Column(db.DateTime, default=datetime.utcnow) update_time = db.Column(db.DateTime, default=datetime.utcnow) counselors = db.relationship('Counselor', backref='duty', lazy='dynamic') lead_class_records = db.relationship('LeadClassRecord', backref='duty', lazy='dynamic') def __init__(self, *args, **kwargs): super(Duty, self).__init__(*args, **kwargs) @staticmethod def insert_duties(): duties = { u'辅导员': (u'岗位:辅导员',), u'实习辅导员': (u'岗位:辅导员',), u'辅助员': (u'岗位:辅助员',) } for r in duties: duty = Duty.query.filter_by(name=r).first() if duty is None: duty = Duty(name=r) duty.desc = duties[r][0] duty.create_time = datetime.utcnow() duty.update_time = datetime.utcnow() db.session.add(duty) db.session.commit()
class Counselor(db.Model): __tablename__ = 'counselors' id = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(100), nullable=False, index=True) religiousname = db.Column(db.String(100)) gender = db.Column(db.String(50)) birthday = db.Column(db.Date) mobile = db.Column(db.String(50)) email = db.Column(db.String(100)) class_id = db.Column(db.Integer, db.ForeignKey('classes.id')) duty_id = db.Column(db.Integer, db.ForeignKey('duties.id')) # 岗位 is_delete = db.Column(db.Integer, default=0) create_user = db.Column(db.Integer) create_time = db.Column(db.DateTime, default=datetime.utcnow) update_user = db.Column(db.Integer) update_time = db.Column(db.DateTime, default=datetime.utcnow) lead_class_records = db.relationship('LeadClassRecord', backref='counselor', lazy='dynamic') training_records = db.relationship('TrainingRecord', backref='counselor', lazy='dynamic') evaluation_records = db.relationship('EvaluationRecord', backref='counselor', lazy='dynamic') def __init__(self, *args, **kwargs): super(Counselor, self).__init__(*args, **kwargs) def __repr__(self): return '<Counselor %r>' % self.username if self.religiousname is None else self.religiousname
class Role(db.Model): __tablename__ = 'roles' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(50), nullable=False, unique=True, index=True) show_name = db.Column(db.String(100)) default = db.Column(db.Boolean, default=False, index=True) permissions = db.Column(db.Integer) users = db.relationship('User', backref='role', lazy='dynamic') def __init__(self, *args, **kwargs): super(Role, self).__init__(*args, **kwargs) @staticmethod def insert_roles(): roles = { 'User': (Permission.USER, True, u'修学处义工'), # 修学处义工权限 'Moderator': (Permission.MODERATOR, False, u'辅导委义工'), # 辅导委义工权限 'Admin': (Permission.ADMIN, False, u'管理员') # 超级管理员权限 } for r in roles: role = Role.query.filter_by(name=r).first() if role is None: role = Role(name=r) role.permissions = roles[r][0] role.default = roles[r][1] role.show_name = roles[r][2] db.session.add(role) db.session.commit() def __repr__(self): return '<Role %r>' % self.name
class Division(db.Model): __tablename__ = 'divisions' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), index=True, unique=True, nullable=False) desc = db.Column(db.Text) update_user = db.Column(db.Integer) create_time = db.Column(db.DateTime, default=datetime.utcnow) update_time = db.Column(db.DateTime, default=datetime.utcnow) departments = db.relationship('Department', backref='division', lazy='dynamic') users = db.relationship('User', backref='division', lazy='dynamic') def __init__(self, *args, **kwargs): super(Division, self).__init__(*args, **kwargs) def __repr__(self): return '<Division %r>' % self.name
class Class(db.Model): __tablename__ = 'classes' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), index=True, unique=True, nullable=False) number = db.Column(db.String(255), unique=True, nullable=False, index=True) # 班级编号 desc = db.Column(db.Text) update_user = db.Column(db.Integer) create_time = db.Column(db.DateTime, default=datetime.utcnow) update_time = db.Column(db.DateTime, default=datetime.utcnow) department_id = db.Column(db.Integer, db.ForeignKey('departments.id')) counselors = db.relationship('Counselor', backref='class_', lazy='dynamic') lead_class_records = db.relationship('LeadClassRecord', backref='class_', lazy='dynamic') def __init__(self, *args, **kwargs): super(Class, self).__init__(*args, **kwargs) def __repr__(self): return '<Class %r>' % self.name def to_json(self): return {'id': self.id, 'name': self.name, 'desc': self.desc, 'number': self.number}
class Department(db.Model): __tablename__ = 'departments' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), index=True, unique=True, nullable=False) desc = db.Column(db.Text) update_user = db.Column(db.Integer) create_time = db.Column(db.DateTime, default=datetime.utcnow) update_time = db.Column(db.DateTime, default=datetime.utcnow) division_id = db.Column(db.Integer, db.ForeignKey('divisions.id')) classes = db.relationship('Class', backref='department', lazy='dynamic') def __init__(self, *args, **kwargs): super(Department, self).__init__(*args, **kwargs) def __repr__(self): return '<Department %r>' % self.name def to_json(self): return {'id': self.id, 'name': self.name, 'desc': self.desc}