(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 ...
随机推荐
- Bash实践:抽样检测数据迁移至Redis集群后的数据一致性
熟悉了一段时间的Bash编程,因此借此任务操作一把bash编程,主要涉及到Redis单节点与Redis集群的操作 1. 任务背景 近日有个任务需要将历史的Redis(主从节点)中的数据迁移至Redis ...
- Visual Studio2017中如何让ADO.NET实体数据模型[EntityFramework]支持MariaDB&MySQL数据源
近期由于工作需要,需要重新修改设计系统的ADO.NET实体数据模型.edmx文件中间,在完成实际中途遇到一些实际使用问题,特此记录. 1. Visual Studio 2017 无法以实体设计模式打开 ...
- 搭建简单FTP
搭建简单FTP 环境 CentOS 7 安装 yum install vsftpd 修改配置文件, 在/etc/vsftpd/vsftpd.conf中添加allow_writeable_chroot= ...
- [转]Newtonsoft JSON how to dynamically change the date format?
本文转自:http://www.howtobuildsoftware.com/index.php/how-do/cg8K/jsonnet-newtonsoft-json-how-to-dynamica ...
- 基于语法分析器GOLD Parser开发的数学表达式计算器
最近发现一款文法分析神器,看完官网(http://goldparser.org/)的介绍后感觉很犀利的样子,于是就拿来测试了一番,写了一个数学表达式分析的小程序,支持的数学运算符如下所示:常规运算:+ ...
- Redis整合spring总结
一:Redis简介: Redis是一个开源(BSD许可)的内存数据结构存储,用作数据库,缓存和消息代理. 简单来说,它是一个以(key,value)的形式存储数据的数据库. 官网:https://re ...
- Ubuntu 16.04 开启BBR加速
BBR(Bottleneck Bandwidth and RTT)是Google推出的一个提高网络利用率的算法,可以对网络进行加速,用来干什么大家心里都有B数 Ubuntu开启BBR的前提是内核版本必 ...
- 互联网轻量级框架SSM-查缺补漏第五天
简言:这个地方我就草草过了,NBA圣诞大战,偷偷看比赛,真香~ 第五章映射器 5.2select元素 自动映射和驼峰映射:MyBatis提供了自动映射功能,在默认的情况下自动映射功能是开启的. 在se ...
- js上传并且预览图片
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 拖动条SeekBar
1TextView tv=(TextView)findViewById(R.id.TV); 2 tv.setMovementMethod(ScrollingMovementMethod.getInst ...