Created
April 2, 2016 20:43
-
-
Save DLSteve/013f9575161787c012d1e029f967c630 to your computer and use it in GitHub Desktop.
Sample Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User(UserMixin, db.Model): | |
__tablename__ = 'users' | |
id = db.Column(db.Integer, primary_key=True) | |
email = db.Column(db.String(64), unique=True, index=True) | |
username = db.Column(db.String(64), unique=True, index=True) | |
password_hash = db.Column(db.String(128)) | |
@property | |
def password(self): | |
raise AttributeError('password is not a readable attribute') | |
@password.setter | |
def password(self, password): | |
self.password_hash = generate_password_hash(password) | |
def verify_password(self, password): | |
return check_password_hash(self.password_hash, password) | |
def __repr__(self): | |
return '<User %r>' % self.username | |
@login_manager.user_loader | |
def load_user(user_id): | |
return User.query.get(int(user_id)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment