refactor(api):移除marshal序列化

This commit is contained in:
zhengxinonly
2021-12-07 20:24:07 +08:00
parent 9490ccb7c0
commit 820ab9f5c6
13 changed files with 282 additions and 172 deletions
+4
View File
@@ -18,6 +18,10 @@ class CompanyDepartment(db.Model, BaseModel):
@staticmethod
def fields():
"""
定义模型的常用输出字段,新手请忽略。可以简化字段序列化操作,
详细操作请查看 flask-restful marshal 的用法
"""
return {
'deptId': fields.Integer(attribute="id"),
'parentId': fields.Integer(attribute="parent_id"),
+2 -18
View File
@@ -21,25 +21,9 @@ class CompanyUser(db.Model, UserMixin, BaseModel):
role = db.relationship('RightsRole', secondary="rt_user_role", backref=db.backref('user'), lazy='dynamic')
def set_password(self, password):
"""设置密码,对密码进行加密存储"""
self.password_hash = generate_password_hash(password)
def validate_password(self, password):
"""校验密码方法"""
return check_password_hash(self.password_hash, password)
@staticmethod
def fields():
return {
'id': fields.Integer,
'username': fields.String,
'realname': fields.String,
'mobile': fields.String,
'avatar': fields.Url,
'comment': fields.String,
# 'password_hash': fields.String,
'enable': fields.Boolean,
# 'dept_id': fields.Integer,
'dept_id': fields.Integer,
'create_at': fields.DateTime,
'update_at': fields.DateTime,
}