models.py (1572B)
1 from datetime import datetime 2 3 from flask_login import UserMixin 4 5 from .server import db, login_manager 6 7 """ function to load a user from database """ 8 @login_manager.user_loader 9 def load_user(user_id): 10 return User.query.get(int(user_id)) 11 12 """ user-struct for 'user'-database """ 13 class User(db.Model, UserMixin): 14 id = db.Column(db.Integer, primary_key=True) 15 type = db.Column(db.String(6), nullable=False, default="client") 16 username = db.Column(db.String(20), unique=True, nullable=False) 17 email = db.Column(db.String(120), unique=True, nullable=False) 18 image_file = db.Column(db.String(20), nullable=False, default='default.jpg') 19 password = db.Column(db.String(60), nullable=False) 20 21 """ course-struct for 'course'-database """ 22 class Course(db.Model): 23 id = db.Column(db.Integer, primary_key=True) 24 name = db.Column(db.String(100), nullable=False) 25 description = db.Column(db.Text, nullable=False) 26 teacher_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) 27 weekday = db.Column(db.Integer, nullable=False) 28 start = db.Column(db.String(10), nullable=False, default=datetime.utcnow) 29 end = db.Column(db.String(10), nullable=False, default=datetime.utcnow) 30 location = db.Column(db.String(120), nullable=False) 31 32 """ course-member-struct for 'coursemember'-database """ 33 class CourseMember(db.Model): 34 id = db.Column(db.Integer, primary_key=True) 35 course_id = db.Column(db.Integer, db.ForeignKey('course.id'), nullable=False) 36 user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)