Fixed #8023 -- Allow filtering of DecimalFields (in models) using strings.
At the same time, checked all other cases of db_prep_value() to ensure they aren't making the same mistake. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8143 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1ba2d6888f
commit
281f2b74bf
|
@ -732,8 +732,8 @@ class DecimalField(Field):
|
||||||
return util.format_number(value, self.max_digits, self.decimal_places)
|
return util.format_number(value, self.max_digits, self.decimal_places)
|
||||||
|
|
||||||
def get_db_prep_value(self, value):
|
def get_db_prep_value(self, value):
|
||||||
return connection.ops.value_to_db_decimal(value, self.max_digits,
|
return connection.ops.value_to_db_decimal(self.to_python(value),
|
||||||
self.decimal_places)
|
self.max_digits, self.decimal_places)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [curry(oldforms.DecimalField, max_digits=self.max_digits, decimal_places=self.decimal_places)]
|
return [curry(oldforms.DecimalField, max_digits=self.max_digits, decimal_places=self.decimal_places)]
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
try:
|
||||||
|
import decimal
|
||||||
|
except ImportError:
|
||||||
|
from django.utils import _decimal as decimal # Python 2.3 fallback
|
||||||
|
|
||||||
class Foo(models.Model):
|
class Foo(models.Model):
|
||||||
a = models.CharField(max_length=10)
|
a = models.CharField(max_length=10)
|
||||||
|
d = models.DecimalField(max_digits=5, decimal_places=3)
|
||||||
|
|
||||||
def get_foo():
|
def get_foo():
|
||||||
return Foo.objects.get(id=1)
|
return Foo.objects.get(id=1)
|
||||||
|
@ -29,7 +35,7 @@ class Whiz(models.Model):
|
||||||
|
|
||||||
__test__ = {'API_TESTS':"""
|
__test__ = {'API_TESTS':"""
|
||||||
# Create a couple of Places.
|
# Create a couple of Places.
|
||||||
>>> f = Foo.objects.create(a='abc')
|
>>> f = Foo.objects.create(a='abc', d=decimal.Decimal("12.34"))
|
||||||
>>> f.id
|
>>> f.id
|
||||||
1
|
1
|
||||||
>>> b = Bar(b = "bcd")
|
>>> b = Bar(b = "bcd")
|
||||||
|
@ -67,5 +73,10 @@ None
|
||||||
>>> w.get_c_display()
|
>>> w.get_c_display()
|
||||||
u''
|
u''
|
||||||
|
|
||||||
|
# Regression test for #8023: should be able to filter decimal fields using
|
||||||
|
# strings (which is what gets passed through from, e.g., the admin interface).
|
||||||
|
>>> Foo.objects.filter(d=u'1.23')
|
||||||
|
[]
|
||||||
|
|
||||||
|
|
||||||
"""}
|
"""}
|
||||||
|
|
Loading…
Reference in New Issue