(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 ...
随机推荐
- WINDOWS安装mysql5.7.20
MSI安装包链接 http://pan.baidu.com/s/1mhI0SMO 提取密码 gaqu 安装前要把老版本的MYSQL卸载干净 之前用官网的archive免安装版安装一直失败,放弃,用MS ...
- resteay上传单个文件/多个文件到本地
代码如下: CADLocalControlle.java package com.xgt.controller; import com.xgt.common.BaseController; impor ...
- liunx下查看日志最实用命令和方法
1.业务系统访问量不是很大的时候,使用这个,有bug的地方操作下,直接看最后操作的日志,就是你刚才操作的地方,好好查bug吧 tail -fn100 catalina.log 查询日志尾部 ...
- Spring ContextLoaderListener
ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息.因为它实现了ServletContextListener这个接口,在web ...
- tomcat 修改 编码
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" ...
- javascript进行base64加密,解密
function Base64() { // private property _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr ...
- PostgreSQL Entity Framework 自动迁移
1.依次添加NuGet包 EntityFramework.Npgsql.EntityFramework6.Npgsql,会自动生成一些配置文件,不过缺少数据库驱动的配置节点: <system.d ...
- Swift可选链
//可选链测试 class Person{ var residence:Residence! var name:String init(name:String){ self.name = name } ...
- RabbitMQ - 任务队列
这次我们试着实现这样一个小程序: 嗯,就是任务队列(task queue).不是将任务集中在一堆并一直等到所有任务一并完成为止,而是将每一个任务封装为一个消息,并将其发送到队列,后台的workers就 ...
- JMS - ActiveMQ的简单使用
首先需要下载ActiveMQ,下面的链接给我们列出了所有版本:http://activemq.apache.org/download-archives.html每个版本为不同的OS提供了链接: 公司电 ...