Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django - How to set default value for DecimalField in django 1.3?

One of my model's field looks like this:

total_amount = models.DecimalField(max_digits=20,decimal_places=4,default=Decimal('0.0000'))

but when I run this command python manage.py syncdb, it shows this error:

NameError: name 'Decimal' is not defined

I have imported from django.db import models, do I need to import any other thing too?
Please Help!

like image 751
MHS Avatar asked Jul 18 '13 08:07

MHS


2 Answers

You need to import Decimal.

from decimal import Decimal
like image 144
falsetru Avatar answered Nov 16 '22 01:11

falsetru


total_amount = models.DecimalField(max_digits=20, decimal_places=4, default=0.0)
like image 23
Hasan Khan Avatar answered Nov 16 '22 00:11

Hasan Khan