1 | from django.db import models
|
---|
2 | from decimal import Decimal
|
---|
3 |
|
---|
4 | class Foo(models.Model):
|
---|
5 | """ A test class, to check DecimalField works
|
---|
6 | >>> type(Decimal('0.00'))
|
---|
7 | <class 'decimal.Decimal'>
|
---|
8 |
|
---|
9 | This fails, however:
|
---|
10 | >>> f = Foo()
|
---|
11 | >>> type(f.decimal)
|
---|
12 | <class 'decimal.Decimal'>
|
---|
13 |
|
---|
14 | I get a unicode string instead
|
---|
15 | Expected:
|
---|
16 | <class 'decimal.Decimal'>
|
---|
17 | Got:
|
---|
18 | <type 'unicode'>
|
---|
19 |
|
---|
20 | Workaround: you can save and reload it:
|
---|
21 | >>> f.save()
|
---|
22 | >>> g = Foo.objects.get(id=f.id)
|
---|
23 | >>> type(g.decimal)
|
---|
24 | <class 'decimal.Decimal'>
|
---|
25 | """
|
---|
26 |
|
---|
27 | decimal = models.DecimalField(decimal_places=2, max_digits=10, default=Decimal("0.00"))
|
---|
28 |
|
---|