当前位置: 首页 > news >正文

flask-admin 在modelview 视图中重写on_model_change 与after_model_change

背景:

当我们在使用flask-admin进行WEB开发时应该第一时间想到的是竟可能使用框架推荐的modelView模型,其次才是自定义模型 baseview,因为只有modelview模型下开发才能最大限度的提高效率。

制作:

1、在modelview视图下框架会通过默认视图进行展示模型信息,有时候因业务需要在模型数据增改时需要做一些前置或者后置操作。

2、框架提供on_model_change和 after_model_change2个函数来分别应模型数据修改前和修改后事件

    def after_model_change(self, form, model, is_created):"""Perform some actions after a model was created or updated andcommitted to the database.Called from create_model after successful database commit.By default does nothing.:param form:Form used to create/update model:param model:Model that was created/updated:param is_created:True if model was created, False if model was updated"""passdef on_model_change(self, form, model, is_created):"""Perform some actions before a model is created or updated.Called from create_model and update_model in the same transaction(if it has any meaning for a store backend).By default does nothing.:param form:Form used to create/update model:param model:Model that will be created/updated:param is_created:Will be set to True if model was created and to False if edited"""pass

注意:a、2个函数的model中都可以拿到当前模型兑换ing表单form 信息和DB模型信息

           b、这2个函数只能在modelview 模型及其子模型中生效

http://www.lryc.cn/news/512212.html

相关文章:

  • Excel粘贴复制不完整的原因以及解决方法
  • 【深度学习环境】NVIDIA Driver、Cuda和Pytorch(centos9机器,要用到显示器)
  • Cocos Creator 3.8.5 正式发布,更小更快更多平台!
  • Python中构建终端应用界面利器——Blessed模块
  • Android 15 状态栏闹钟图标不显示问题修复
  • 数据采集背后的效率革命:如何优化你的爬虫性能
  • 【Compose multiplatform教程06】用IDEA编译Compose Multiplatform常见问题
  • 《计算机组成及汇编语言原理》阅读笔记:p128-p132
  • 使用 OpenCV 在图像中添加文字
  • 实现某海外大型车企(T)Cabin Wi-Fi 需求的概述 - 4
  • Linux系统:内核态与用户态的深层思考
  • # 光速上手 - JPA 原生 sql DTO 投影
  • ASP.NET Web应用程序出现Maximum request length exceeded报错
  • HTML——16.相对路径
  • windows 默认的消息ID有那些---我与大模型对话
  • CSV vs 数据库:爬虫数据存储的最佳选择是什么
  • 编译原理学习笔记——CH7-Runtime Environments运行时环境
  • 机器学习DAY7: 特征工程和特征选择(数据预处理)(完)
  • vue3动态加载组件
  • 12.29 redis缓存一致性
  • SqlSugar配置连接达梦数据库集群
  • 评分模型在路网通勤习惯分析中的应用——提出问题(1)
  • 使用 OpenCV 绘制线条和矩形
  • npm 切换镜像源
  • CSS(四)display和float
  • MMaudio AI:如何通过 AI 实现精准的视频到音频合成
  • SQL进阶技巧:如何分析双重职务问题?
  • OpenCV相机标定与3D重建(37)计算两幅图像之间单应性矩阵(Homography Matrix)的函数findHomography()的使用
  • Nacos配置管理+共享配置、配置热更新
  • asp.net core系统记录当前在线人数