Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set defauls value for DecimalField as 0.00

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?

like image 938
Stephen M Avatar asked Sep 15 '11 19:09

Stephen M


People also ask

What is the default value for decimal?

The default value of Decimal is 0.

What is the default value for decimal in SQL?

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.


1 Answers

Put quotes around the number:

Decimal('0.00')
like image 127
jathanism Avatar answered Sep 27 '22 15:09

jathanism