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) isAdmin = db.Column(db.Boolean, nullable=False, default=False) words = db.relationship('Word', backref='contributor', lazy=True) # posts = db.relationship('Post', backref='author', lazy=True) def get_reset_token(self, expires_sec=1800): s = Serializer(current_app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(current_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 "User('{}', '{}', '{}')".format(self.username, self.email, self.image_file)
class Wotd(db.Model): uid = db.Column(db.Integer(), primary_key=True, unique=True) date = db.Column(db.String(), nullable=False, default=get_date()) # JP word, its romanji, and its definition. All required. wotd = db.Column(db.String(), nullable=False, unique=True) romaji = db.Column(db.String(), nullable=False) defn = db.Column(db.String(), nullable=False) # Not required, but nice to have example = db.Column(db.Text()) classification = db.Column(db.String(20)) def __repr__(self): return '<WOTD: %r:%r:%r>' % (self.uid, self.date, self.wotd)
class User(UserMixin, db.Model): username = db.Column(db.String(80), nullable=False, primary_key=True) password = db.Column(db.String(120)) def __repr__(self): return '<user %r:%r>' % (self.username, self.password) def set_password(self, password): self.password = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password, password) def get_id(self): return self.username
class PartOfSpeech(db.Model): id = db.Column(db.Integer, primary_key=True) partOfSpeech = db.Column(db.String(100), nullable=False) words = db.relationship('Word', backref='part_o_speech', lazy=True) def __repr__(self): return "{}".format(self.partOfSpeech)
class Word(db.Model): id = db.Column(db.Integer, primary_key=True) word = db.Column(db.String(100), nullable=False) partOfSpeech_id = db.Column(db.Integer, db.ForeignKey('part_of_speech.id'), nullable=False) definition = db.Column(db.Text, nullable=False) exampleSentence = db.Column(db.Text, nullable=False) ipa = db.Column(db.Text, nullable=True) date_added = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) date_published = db.Column(db.Date, nullable=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True) def __repr__(self): return "Word('{}', '{}', '{}')".format(self.word, self.part_o_speech, self.contributor)
class Content(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) private_title = db.Column(db.String(100), nullable=False) content = db.Column(db.Text, nullable=False) isActive = db.Column(db.Boolean, nullable=False, default=False)