[Django]-Django – How to set default value for DecimalField in django 1.3?

35👍

You need to import Decimal.

from decimal import Decimal

3👍

total_amount = models.DecimalField(max_digits=20, decimal_places=4, default=0.0)

0👍

When you are getting error about default in Decimal Field you have to also pay your attension that max_digits e.x. 9 means 8 digit before dot and 1 digit after dot.

so max_digits=5 and default=Decimal(‘99999.0’) (6digits at all including trailing 0 at the end of decimal) is Invalid Decimal and Decimal(‘9999.0’) is correct

👤Rafał

Leave a comment