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. 深入redis内部--内存管理

    1. Redis内存管理通过在zmalloc.h和zmalloc.c中重写c语言对内存的管理来完成的. redis内存管理 c内存管理 原型 作用 zmalloc malloc void *mallo ...

  2. 解决ajax请求返回Json无法解析"\"字符的问题

    原因:获取身份证信息,涉及图片路径,存在“\”字符,导致Json解析错误 解决思路:将返回类型从"json"改成"text",此时返回的数据类型变成字符串,将字 ...

  3. Golang教程:类型

    下面是 Go 支持的基本类型: bool Numeric Types  int8, int16, int32, int64, int uint8,uint16,uin32,uint64, uint f ...

  4. (转载).NET的五层架构

    我们刚开始学习架构的时候,首先会想到分层的概念,分层架构比较经典的是三层架构,那么,什么是三层架构呢?它包括表现层,业务层,数据访问层:而对于一个新手来说,从抽象意义上的三层架构,逻辑上就划分为三个层 ...

  5. 手机UA识别

    整理手机UA识别如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  6. CentOS 6 安装 MySQL 8.0.+

    1.先查询是否安装MySQL 大多数centos 6 自带 MySQL5.1 命令: rpm -qa|grep mysql 执行: [root@lifan ~]# rpm -qa|grep mysql ...

  7. 第2章 css边框属性

    圆角效果 border-radius border-radius是向元素添加圆角边框. 使用方法: border-radius:10px; /* 所有角都使用半径为10px的圆角 */ border- ...

  8. flex固定底部栏

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. Jquery trigger 与 triggerHandler

    secying Jquery trigger与triggerHandler trigger: 在每一个匹配的元素上触发某类事件(即触发jQuery对象集合中每一个元素). 这个函数也会导致浏览器同名的 ...

  10. 动画演示10个有趣但毫无用处的Linux命令

    Linux最强大的一个特征就是它有大量的各种小命令工具,这也可以称做是它最有趣的一个地方了.在这些大量的有用的命令和脚本中,你会发现有少部 分命令工具不那么有用的——如果你不愿意说是完全没用处的话.你 ...