Python Django 2.0 DecimalField“;确保小数点前不超过3位;

Python Django 2.0 DecimalField“;确保小数点前不超过3位;,python,django,django-models,django-2.0,Python,Django,Django Models,Django 2.0,“我的金额”列属性设置为最大位数=13,小数位数=7,因为从技术上讲,您可以拥有类似10000.0000001比特币的内容 当我尝试在我的表单上输入并提交0.1比特币时,我会出现以下错误: 确保小数点前的数字不超过3位 这不符合预期:0.1不超过3位数,即使是,我也应该能够设置超过3位数。。这里发生了什么 models.py class Transactions(models.Model): user = models.ForeignKey(User, on_delete = mo

“我的金额”列属性设置为最大位数=13,小数位数=7,因为从技术上讲,您可以拥有类似10000.0000001比特币的内容

当我尝试在我的表单上输入并提交0.1比特币时,我会出现以下错误:

确保小数点前的数字不超过3位

这不符合预期:0.1不超过3位数,即使是,我也应该能够设置超过3位数。。这里发生了什么

models.py

class Transactions(models.Model):   
    user = models.ForeignKey(User, on_delete = models.CASCADE)  
    coin = models.CharField(max_length = 64)  
    buysell = models.CharField(default = 'buy', max_length = 4)
    amount = models.DecimalField(max_digits = 13, decimal_places = 7)  
    trade_price = models.DecimalField(max_digits = 5, decimal_places = 2)
    trade_date = models.DateTimeField(auto_now = True) 
forms.py

class TransactionForm(forms.ModelForm): 

    CHOICES = ((1, 'Buy'), (2, 'Sell'),)

    coin = forms.ModelChoiceField(queryset = Coin.objects.all()) 
    buysell = forms.ChoiceField(choices = CHOICES)

    field_order = ['buysell', 'coin', 'amount', 'trade_price']

    class Meta:
        model = Transactions
        fields = {'buysell', 'coin', 'amount', 'trade_price'}

正如您所说,
0.1
在小数点前的位数不超过3位,因此不应给出该错误。因此,错误可能来自不同的领域

您没有说哪个字段给出了错误,或者您为其他字段提交了什么值,但我怀疑问题出在您的
trade\u price
字段上

trade_price = models.DecimalField(max_digits = 5, decimal_places = 2)

目前,它支持的最大值为
999.99
。因此,如果您输入
trade\u price=10000
,您将得到
不超过3位的错误。

尝试这样传递您的号码:
number=round(0.1,7)
。您确定后端得到的是
0.1
。您能否通过检查请求数据来确认请求。似乎还有更多的东西要送