"""Cookie管理Schema""" from flask_marshmallow.sqla import SQLAlchemyAutoSchema from marshmallow import fields from applications.extensions import ma from applications.models import CookieUser, CookieSite class CookieUserManageSchema(SQLAlchemyAutoSchema): """登录用户管理用:序列化为表格数据 / 表单回填""" class Meta: model = CookieUser include_fk = True load_instance = True class CookieSiteManageSchema(SQLAlchemyAutoSchema): """登录网站管理用:序列化为表格数据 / 表单回填""" # 关联登录用户的显示名(视图层预先挂到对象上的 _cookie_username) cookie_username = fields.Method('get_cookie_username') class Meta: model = CookieSite include_fk = True load_instance = True def get_cookie_username(self, obj): return getattr(obj, '_cookie_username', '') or ''