(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 ...
随机推荐
- java中四种引用类型(对象的强、软、弱和虚引用)
对象的强.软.弱和虚引用在JDK 1.2以前的版本中,若一个对象不被任何变量引用,那么程序就无法再使用这个对象.也就是说,只有对象处于可触及(reachable)状态,程序才能使用它.从JDK 1.2 ...
- [转]Add Bootstrap Glyphicon to Input Box
本文转自:http://stackoverflow.com/questions/18838964/add-bootstrap-glyphicon-to-input-box How can I add ...
- Hadoop实战之二~ hadoop作业调度详解(1)
对Hadoop的最感兴趣的地方,也就在于Hadoop的作业调度了,在正式介绍如何搭建Hadoop之前,深入理解一下Hadoop的作业调度很有必要.我们不一定能用得上Hadoop,但是如果理通顺Hado ...
- Shiro - 与Spring集成
本文是针对web应用web.xml: <filter> <filter-name>shiroFilter</filter-name> <filter-clas ...
- nginx+nodejs+mysql+memcached服务器后台架设centos6.5
需要的下面四个工具最好都采用yum安装,不要采用编译安装的方法,因为编译安装会导致某些依赖关系丢失. nginx 作为HTTP和反向代理,处理静态页面,动态服务交由nodejs服务. nodejs作为 ...
- Node.js学习笔记(三) --- package.json 及cnpm
一.包 Nodejs 中除了它自己提供的核心模块外,我们可以自定义模块,也可以使用第三方的模块.Nodejs 中第三方模块由包组成,可以通过包来对一组具有相互依赖关系的模块进行统一管理. 完全符合 ...
- Linux下查看Tomcat的控制台输出信息
Linux下查看Tomcat的控制台输出信息 首先使用SSH连接到数据库,然后点击window创建一个new terminal, 进入tomcat/logs/文件夹下,输出控制台信息,命令如下: cd ...
- Oracle易忘知识点记录
1.SQL Select语句完整的执行顺序: ①from子句组装来自不同数据源的数据: ②where子句基于指定的条件对记录行进行筛选: ③group by子句将数据划分为多个分组: ④使用聚集函数进 ...
- ApplicationHost.config文件被破坏导致IIS崩溃
“”Application Host Helper Service 在尝试删除历史目录“C:\inetpub\history\CFGHISTORY_0000000475”时遇到错误.将跳过并忽略此目录 ...
- 医药箱APP静态小项目
花费了10天时间,纯手写一个医药箱APP静态小项目,里面有上拉加载.左右滑动.弹出层淡入淡出等效果,主要是练习. 以下是一部分页面效果图: 我用的是谷歌的开发者工具的手机端模拟器. 里面需要优化的地方 ...