Skip to content

Instantly share code, notes, and snippets.

@piyonishi
Created September 23, 2018 19:37
Show Gist options
  • Save piyonishi/1b1b6475df66fef200075ddd518d90ab to your computer and use it in GitHub Desktop.
Save piyonishi/1b1b6475df66fef200075ddd518d90ab to your computer and use it in GitHub Desktop.
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), unique=True, index = True)
email = db.Column(db.String(120), unique=True, index = True)
image_url = db.Column(db.String(120), unique=True, index =True)
def __init__(self, name, password, email, image_url):
self.name = name
self.set_password(password)
self.email = email
self.image_url = image_url
def set_password(self, password):
self.pw_hash = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.pw_hash, password)
def __repr__(self):
return '<User %r>' % self.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment