(fields.E130) DecimalFields must define a 'decimal_places' attribute.
DecimalField类型:
固定精度的十进制数,一般用来存金额相关的数据。额外的参数包括DecimalField.max_digits(整个数字的长度)和DecimalField.decimal_places(小数点后面的有效位数)
模型定义时, DecimalField类型字段如下定义:
aaf_1kg_all = models.DecimalField(blank=True, null=True)
报错:
(fields.E130) DecimalFields must define a 'decimal_places' attribute.
(fields.E132) DecimalFields must define a 'max_digits' attribute.
即: DecimalFields字段的“decimal_places”() 和 “max_digits” 属性必须被定义,不能忽略。
那么修改一下:
aaf_1kg_all = models.DecimalField(blank=True, null=True, max_digits=10, decimal_places=10)
报错:
Traceback (most recent call last):
[...]
File ".../django/db/backends/utils.py", line 200, in format_number
value = value.quantize(decimal.Decimal(".1") ** decimal_places, context=context)
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
这里注意:
参数max_digits的值必须大于decimal_places的值。
0.10000 有效位是5位,但是1.00000的有效位是6位。
因此,如果max_digits=5, decimal_places=5, 那么,任何大于或者等于1的值出现都将报错。
正面举例:
max_digits=2, decimal_places=2
那么该字段可表示数值范围为0.00 - 99.99
(fields.E130) DecimalFields must define a 'decimal_places' attribute.的更多相关文章
- Python升级3.6 强力Django+Xadmin打造在线教育平台
第 1 章 课程介绍 1-1 项目演示和课程介绍: 第 2 章 Windows下搭建开发环境 2-1 Pycharm.Navicat和Python解释器的安装: Pycharmhttp://www.j ...
- 【转载】#470 Define Your Own Custom Attribute
You can use predefined attributes to attach metadata to type members. You can also define a custom a ...
- Odoo Documentation : Fields
Fields Basic fields class openerp.fields.Field(string=None, **kwargs) The field descriptor contains ...
- 再次深入 C# Attribute
了解attribute Attribute 只是将一些附加信息与某个目标元素关联起来的方式. Attribute 是一个类,这个类可以提供一些字段和属性,不应提供公共方法,事件等.在定义attribu ...
- html tags and attribute集参考
cite 表示引用到某一本书籍名称,默认样式为斜体,q 表示直接引用到里面的话,大块的引用使用block默认样式将增加“双引号” ,关键的词用<b>默认为粗体:一些技术术语则用<i& ...
- Property attribute.
class property(object): """ Property attribute. fget function to be used for getting ...
- Django Model field reference
===================== Model field reference ===================== .. module:: django.db.models.field ...
- Android Lint Checks
Android Lint Checks Here are the current list of checks that lint performs as of Android Studio 2.3 ...
- python之旅3
1 collections系列 方法如下 class Counter(dict): '''Dict subclass for counting hashable items. Sometimes ca ...
随机推荐
- OpenGL初识
OpenGL 概念 OpenGL提供的是一系列接口, 它是指一个规范, OpenGL规范严格规定了每个函数该如何执行, 以及它们的输出值, 具体的实现是由各个显示设备厂商, 它作为本地系统库直接运行在 ...
- Mybatisplus分页插件的使用
一.加依赖: <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus ...
- js验证港澳居民通行证号码是否合规
需求:最近要做实名验证的功能,但是验证我们要验证严谨一点,参考了网上关于验证港澳居民通行证号码的代码,总结一下. 代码: function checkHKMacao(code){ var tip = ...
- explode 把字符串打散为数组
// 显示的字段列表 $smarty->assign('field_show', explode(',',$list_name)); explode(separator,string,limit ...
- servlet开发(四)之ServletContext
接上一篇. 2.3.4 利用ServletContext对象读取资源文件 比如我们要读取web项目中的配置文件. 项目目录结构如下: 使用ServletContext对象读取资源文件的示例代码如下: ...
- 中南oj 1213: 二叉树结点公共祖先
1213: 二叉树结点公共祖先 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 159 Solved: 87 [Submit][Status][Web ...
- svn 创建本地仓库
1. svnadmin create ~/repository 2. svnserve -d -r ~/repository 3. svn checkout file://~/repository $ ...
- java设计模式-观察者模式学习
最近学习了设计模式中的观察者模式,在这里记录下学习成果. 观察者模式,个人理解:就是一个一对多模型,一个主体做了事情,其余多个主体都可以观察到.只不过这个主体可以决定谁去观察他,以及做什么事情可以给别 ...
- 在mysql语句中为什么要加反引号
在MySQL语句中我们有时候经常会遇到反引号(``),刚开始的时候不知道什么意思,他是什么作用呢? Select * from `member` order by posts desc limit 0 ...
- 微信小程序request请求之GET跟POST的区别
1.GET 例子: wx.request({ url: 'test.php', //仅为示例,并非真实的接口地址 data: { x: '' , y: '' }, header: { 'content ...