我有这样的模型:
class User(db.Model):
__tablename__ = 'users'
__table_args__ = {'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8'}
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True)
email = db.Column(db.String(120), unique=True)
_password = db.Column('password', db.String(80))
def __init__(self, username = None, email = None, password = None):
self.username = username
self.email = email
self._set_password(password)
def _set_password(self, password):
self._password = generate_password_hash(password)
def _get_password(self):
return self._password
def check_password(self, password):
return check_password_hash(self._password, password)
password = db.synonym("_password", descriptor=property(_get_password, _set_password))
def __repr__(self):
return '<User %r>' % self.username
我有模型视图:
class UserAdmin(sqlamodel.ModelView):
searchable_columns = ('username', 'email')
excluded_list_columns = ['password']
list_columns = ('username', 'email')
form_columns = ('username', 'email', 'password')
但无论我做什么,当我编辑用户信息时,flask 管理员都没有显示密码字段。有什么办法吗?甚至只是为了编辑哈希码。