使用SQLAlchemy操作MYSQL黑科技之 属性订制
时间:2021-07-01 10:21:17
帮助过:10人阅读
class Role(UserMixin, db.Model):
2 __tablename__ =
‘Role‘
3 id = db.Column(db.Integer, primary_key=
True)
4 username = db.Column(db.String(64), nullable=
True)
5 role = db.Column(db.String(64), nullable=
True)
6 password = db.Column(db.String(64), nullable=
True)
7 password_hash = db.Column(db.String(128), nullable=
True)
8
9 role_art = db.relationship(
‘Article‘, backref=
‘roleart‘)
10 role_com = db.relationship(
‘Comment‘, backref=
‘rolecom‘)
11
12 @property
13 def password(self):
14 raise AttributeError(
‘password is not readable attribute‘) #没有可读的明文密码属性
15
16 @password.setter #设置 哈希后的密码值
17 def password(self, password):
18 self.password_hash =
generate_password_hash(password)
19
20 def verify_password(self, password):
21 return check_password_hash(self.password_hash, password)
使用SQLAlchemy操作MYSQL黑科技之 属性订制
标签:哈希 set com ada pre logs 黑科技 code article