I'm trying to have the default value for several DecimalFields defined as 0.00
in my model class, but even when I have this:
price = models.DecimalField(max_digits=8, decimal_places=2,
default=Decimal(0.00))
I'm getting an error when processing the form:
ValidationError
[u'This value must be a decimal number.']
From the error page, I can see that the issue is that the save method gets u''
for the empty fields. How can I have 0.00 being stored?
The default value of Decimal is 0.
In standard SQL, the syntax DECIMAL( M ) is equivalent to DECIMAL( M ,0) . Similarly, the syntax DECIMAL is equivalent to DECIMAL( M ,0) , where the implementation is permitted to decide the value of M . MySQL supports both of these variant forms of DECIMAL syntax. The default value of M is 10.
Put quotes around the number:
Decimal('0.00')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With