Stephen M
Stephen M

Reputation: 819

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?

Upvotes: 12

Views: 7185

Answers (1)

jathanism
jathanism

Reputation: 33716

Put quotes around the number:

Decimal('0.00')

Upvotes: 13

Related Questions