Choices in DecimalField - django 1.8.

602 views
Skip to first unread message

Elton Pereira

unread,
Apr 20, 2015, 1:44:30 PM4/20/15
to django...@googlegroups.com
In the model below, using the Django admin, no matter what value I choose, it always displays the default value. But writes the correct value in the  database. Am I doing something wrong or is this a bug?

TENSAO_220 = Decimal(220)
TENSAO_110 = Decimal(110)
TENSOES = ((TENSAO_220, '220 volts'),
           (TENSAO_110, '110 volts'))

class Equipamento(models.Model):
    nome = models.CharField(max_length=128)
  tensao = models.DecimalField(max_digits=8,
                               decimal_places=3,
                               choices=TENSOES,
                               default=TENSAO_220)

Thanks!

Gordon Wrigley

unread,
Sep 19, 2017, 7:27:42 AM9/19/17
to Django users
In case anyone else ends up here, I've found that it's very sensitive to how you specify the Decimal, so in my example Decimal('20.00') worked but Decimal('20') and Decimal(20) did not.
Reply all
Reply to author
Forward
0 new messages