序列化类移到models里,简化代码

This commit is contained in:
mkg
2021-04-29 13:09:10 +08:00
parent 8f4054e576
commit 3d5e4b9e9b
14 changed files with 123 additions and 157 deletions
+13 -1
View File
@@ -1,7 +1,9 @@
import datetime
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
from applications.models import db
from applications.models import db, ma
from marshmallow import fields
from applications.models import admin_user_role
class User(db.Model, UserMixin):
@@ -22,3 +24,13 @@ 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()