{{{
class PatronLevelForm(forms.Form):
name = forms.CharField()
lower_threshold = forms.DecimalField(max_digits=20,
decimal_places=2)
}}}
In a view, set up some initial data:
{{{
form = PatronLevelForm(initial={'name': 'Valued Donor', 'lower_threshold':
Decimal(0.01),},)
}}}
The Decimal gets cast to float and request.POST ends up looking like this:
{{{
<QueryDict: {u'name': [u'Valued Donor'], u'lower_threshold':
[u'0.01000000000000000020816681711721685132943093776702880859375']}>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27907>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => invalid
Comment:
The issue is in your code, not in Django. You need to initialize the
`Decimal` with a string `Decimal('0.01')` rather than a float.
--
Ticket URL: <https://code.djangoproject.com/ticket/27907#comment:1>
Comment (by Steven L Smith):
Replying to [comment:1 Tim Graham]:
> The issue is in your code, not in Django. You need to initialize the
`Decimal` with a string `Decimal('0.01')` rather than a float.
Wow... you're absolutely right, and I'm an idiot... I can't believe that
a.) I didn't notice that; and b.) I actually submitted a ticket on it.
Sorry for wasting your time.
Need more coffee! :-)
--
Ticket URL: <https://code.djangoproject.com/ticket/27907#comment:2>