使用flask-restful实现数据校验与序列化3

This commit is contained in:
zhengxinonly
2021-06-27 19:27:08 +08:00
parent e9bd8a17a0
commit e3dd5458ad
23 changed files with 517 additions and 1202 deletions
-17
View File
@@ -27,20 +27,3 @@ class User(db.Model, UserMixin):
def validate_password(self, password):
return check_password_hash(self.password_hash, password)
# 用户models的序列化类
class UserSchema(ma.Schema):
id = fields.Integer()
username = fields.Str()
realname = fields.Str()
enable = fields.Integer()
create_at = fields.DateTime()
update_at = fields.DateTime()
dept = fields.Method("get_dept")
def get_dept(self, obj):
from applications.models import Dept
if obj.dept_id != None:
return Dept.query.filter_by(id=obj.dept_id).first().dept_name
else:
return None