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.的更多相关文章

  1. Python升级3.6 强力Django+Xadmin打造在线教育平台

    第 1 章 课程介绍 1-1 项目演示和课程介绍: 第 2 章 Windows下搭建开发环境 2-1 Pycharm.Navicat和Python解释器的安装: Pycharmhttp://www.j ...

  2. 【转载】#470 Define Your Own Custom Attribute

    You can use predefined attributes to attach metadata to type members. You can also define a custom a ...

  3. Odoo Documentation : Fields

    Fields Basic fields class openerp.fields.Field(string=None, **kwargs) The field descriptor contains ...

  4. 再次深入 C# Attribute

    了解attribute Attribute 只是将一些附加信息与某个目标元素关联起来的方式. Attribute 是一个类,这个类可以提供一些字段和属性,不应提供公共方法,事件等.在定义attribu ...

  5. html tags and attribute集参考

    cite 表示引用到某一本书籍名称,默认样式为斜体,q 表示直接引用到里面的话,大块的引用使用block默认样式将增加“双引号” ,关键的词用<b>默认为粗体:一些技术术语则用<i& ...

  6. Property attribute.

    class property(object): """ Property attribute. fget function to be used for getting ...

  7. Django Model field reference

    ===================== Model field reference ===================== .. module:: django.db.models.field ...

  8. Android Lint Checks

    Android Lint Checks Here are the current list of checks that lint performs as of Android Studio 2.3 ...

  9. python之旅3

    1 collections系列 方法如下 class Counter(dict): '''Dict subclass for counting hashable items. Sometimes ca ...

随机推荐

  1. chmod修改文件的权限/chown修改文件和目录的所有者(转)

    ll指令的显示的信息为(当前目录下只有nameservice1一个目录): drwxr-xr-x 3 hdfs hdfs 4096 4月 14 16:19 nameservice1 上述信息分别表示: ...

  2. php 命名空间与文件引入

    问题描述:这两天试着自己写一些东西,也是为了复习一下忘了的PHP基础知识,但是写到命名空间的时候遇到了一点问题,在这记录一下:当我写好文件之后,添加了命名空间,结果一直提示命名空间下类不存在,一直以为 ...

  3. spring中增加自定义配置支持

    spring.schemas 在使用spring时,我们会首先编写spring的配置文件,在配置文件中,我们除了使用基本的命名空间http://www.springframework.org/sche ...

  4. T_SQL 语句想已有数据表添加约束

    如果向存在数据的表里添加约束,有可能会出现数据不符合检查约束而造成添加约束失败. 如: USE DEmo--指向当前操作的数据库 GO ALTER TABLE Employee ADD CONSTRA ...

  5. C# xml操作word-->word转2003xml

    1.第一步,准备word模版

  6. web.xml配置文件中async-supported报错解决

    项目中配置spring时async-supported报错: 是因为<async-supported>true</async-supported>是web.xml 3.0的新特 ...

  7. Java生成验证码(一)

    一.为什么要使用验证码     我们要通过验证码,由用户肉眼识别其中的验证码信息,从而区分用户是人还是计算机.    二.什么是验证码     验证码:是一种区分用户是计算机还是人的公共全自动程序. ...

  8. 抽象工厂模式的C++、Java实现

    1.抽象工厂模式UML 图1. 抽象工厂模式的UML 2.C++实现 C++实现类图为: 图2. 抽象工厂模式的C++实现类图 其中,AbstractFactory的实现代码为: //抽象工厂类基类. ...

  9. php字符集转换

    PHP通过iconv将字符串从GBK转换为UTF8字符集. 1. iconv()介绍 iconv函数可以将一种已知的字符集文件转换成另一种已知的字符集文件.例如:从GB2312转换为UTF-8. ic ...

  10. css美化checkbox