On 05/11/2011 03:01 PM, Nan wrote:
Using Django 1.2.3, I recently declared a DecimalField on a model, and it happily accepts a float as its default value, but it won't filter on a float (it throws a TypeError instead). Is there a reason for this inconsistency?
DecimalField subclasses Field, which forces the return value into unicode before returning it. This would explain why it accepts a default value of a float, but it's still technically incorrect to provide a float as a default value for a DecimalField.
It is impossible to use a floating-point number to look up a Decimal, just because it is. That's why you can't look it up.
It does look like a bit of a discrepancy, but the answer is that you should never be using floats with Decimal or DecimalField objects anyway. Even if it appears to work, there's always a very real chance that you think you're putting into your database isn't actually what you're putting into your database. Either pass a Decimal object or a string as the default value to your DecimalField.
Shawn http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/__init__.py -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.