daily pastebin goal
67%
SHARE
TWEET

relationship

dongocanh96 Nov 5th, 2018 129 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from blog import login
  2. from blog import db
  3. from datetime import datetime
  4. from flask_login import UserMixin
  5.  
  6.  
  7. @login.user_loader
  8. def load_user(id):
  9.     return User.query.get(int(id))
  10.  
  11.  
  12. class User(UserMixin, db.Model):
  13.     id = db.Column(db.Integer, primary_key=True)
  14.     access_level = db.Column(db.Integer)
  15.     username = db.Column(db.String(64), index=True, unique=True)
  16.     password = db.Column(db.String(128))
  17.     fullname = db.Column(db.String(128), index=True)
  18.     email = db.Column(db.String(120), index=True, unique=True)
  19.     phone_number = db.Column(db.String(10), index=True, unique=True)
  20.     homework = db.relationship("HomeWork", backref="author", lazy="dynamic")
  21.     answer = db.relationship("Solution", backref="author", lazy="dynamic")
  22.  
  23.     def __repr__(self):
  24.         return "<User {}>".format(self.username)
  25.  
  26.     def check_password(self, password):
  27.         return self.password == password
  28.  
  29.     def is_teacher(self):
  30.         return self.access_level == 1
  31.  
  32.  
  33. class HomeWork(db.Model):
  34.     id = db.Column(db.Integer, primary_key=True)
  35.     name = db.Column(db.String(32))
  36.     data = db.Column(db.LargeBinary)
  37.     timestamp = db.Column(db.DateTime, index=True, default=datetime.now)
  38.     user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
  39.  
  40.  
  41.    
  42. class Solution(db.Model):
  43.     id = db.Column(db.Integer, primary_key=True)
  44.     timestamp = db.Column(db.DateTime, index=True, default=datetime.now)
  45.     data = db.Column(db.LargeBinary)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top