class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) posts = db.relationship('Post', backref='author', lazy=True) def get_reset_token(self, expires_sec=1800): s = Serializer(app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class Vak(db.Model): vak_id = db.Column(db.Integer(), primary_key=True) vakcode = db.Column(db.String(225), unique=True, nullable=False) vaknaam = db.Column(db.String(225), unique=True, nullable=False) presentie = db.relationship('Presentie', backref='vak', lazy=True) def __repr__(self): return f"Vak('{self.vakcode}', '{self.vaknaam}')"
class Products(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') price = db.Column(db.String(10), nullable=False) content = db.Column(db.Text, nullable=False) category = db.Column(db.String(20), nullable=False) def __repr__(self): return f"Products('{self.title}', '{self.price}', '{self.image_file}')"
class Student(db.Model): student_id = db.Column(db.Integer(), primary_key=True) naam = db.Column(db.String(225), nullable=False) voornaam = db.Column(db.String(225), nullable=False) studentnummer = db.Column(db.String(225), unique=True, nullable=False) richting = db.Column(db.String(225), nullable=False) cohort = db.Column(db.Integer(), nullable=False) leerjaar = db.Column(db.String(30), nullable=False) presentie = db.relationship('Presentie', backref='student', lazy=True) def __repr__(self): return f"Student('{self.studentnummer}', '{self.naam}', '{self.voornaam}')"
class Presentie(db.Model): pres_id = db.Column(db.Integer(), primary_key=True) vak_id = db.Column(db.Integer(), db.ForeignKey('vak.vak_id'), nullable=False) student_id = db.Column(db.Integer(), db.ForeignKey('student.student_id'), nullable=False) presentie = db.Column(db.String(30), nullable=False) blok = db.Column(db.String(30), nullable=False) datum = db.Column(db.DateTime, nullable=False, default=datetime.now) def __repr__(self): return f"('{self.student_id}', '{self.vak_id}', '{self.datum}', '{self.presentie}')"
class User(db.Model, UserMixin): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) postingans = db.relationship('Post', backref='penulis', lazy=True) def __repr__(self): # return f"User('{self.username}','{self.email}','{self.image_file}')" return "User {}, {}, {} ".format(self.username, self.email, self.image_file)
class Post(db.Model): # __tablename__ = 'post' id = db.Column(db.Integer, primary_key=True) judul = db.Column(db.String(100), nullable=False) tgl_post = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) konten = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return "Post {}, {} ".format(self.judul, self.tgl_post)
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post('{self.title}', '{self.date_posted}')"