我在模型上定义了一个 DecimalField,其 decimal_places 属性等于 max_digits 属性(用于存储 < 1 的值),如下所示:
class MyModel(Model):
my_field = DecimalField(max_digits=5, decimal_places=5)
在一个表单中(例如 django 管理站点),这个字段不会取 0,我得到以下错误:
Ensure that there are no more than 0 digits before the decimal point.
但它需要 0.0 :/
有人遇到同样的问题吗?我找不到关于它的帖子。这是错误还是这种行为有原因?
最佳答案
max_digit = 小数点后的位数 + 小数点前的位数。 因此,如果 max_digit == decimal_digit,则小数点前的位数最多为 0。
关于如果 decimal_places == max_digits,Django DecimalField 不接受 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38118250/