The admin allows filtering objects by edting the url in the browser window.
Eg: http://youraddress/admin/yourapp/yourmodel/?yourdecimalfield__lt=20
When filtering on a decimal field, changeset #7560 breaks this with the following stacktrace:
File "C:\packages\Python-2.5\lib\site-packages\django\core\handlers\base.py" in get_response
87. response = callback(request, *callback_args, **callback_kwargs)
File "C:\packages\Python-2.5\lib\site-packages\django\contrib\admin\views\decorators.py" in _checklogin
61. return view_func(request, *args, **kwargs)
File "c:\develop\frepple\contrib\django\freppledb\utils\report.py" in view_report
302. counter = counter.filter( **{smart_str(key): value} )
File "C:\packages\Python-2.5\lib\site-packages\django\db\models\query.py" in filter
479. return self._filter_or_exclude(False, *args, **kwargs)
File "C:\packages\Python-2.5\lib\site-packages\django\db\models\query.py" in _filter_or_exclude
497. clone.query.add_q(Q(*args, **kwargs))
File "C:\packages\Python-2.5\lib\site-packages\django\db\models\sql\query.py" in add_q
1176. can_reuse=used_aliases)
File "C:\packages\Python-2.5\lib\site-packages\django\db\models\sql\query.py" in add_filter
1123. self.where.add((alias, col, field, lookup_type, value), connector)
File "C:\packages\Python-2.5\lib\site-packages\django\db\models\sql\where.py" in add
48. params = field.get_db_prep_lookup(lookup_type, value)
File "C:\packages\Python-2.5\lib\site-packages\django\db\models\fields\__init__.py" in get_db_prep_lookup
242. return [self.get_db_prep_value(value)]
File "C:\packages\Python-2.5\lib\site-packages\django\db\models\fields\__init__.py" in get_db_prep_value
736. self.decimal_places)
File "C:\packages\Python-2.5\lib\site-packages\django\db\backends\__init__.py" in value_to_db_decimal
302. return util.format_number(value, max_digits, decimal_places)
File "C:\packages\Python-2.5\lib\site-packages\django\db\backends\util.py" in format_number
126. return u"%.*f" % (decimal_places, value)
Exception Type: TypeError at /admin/input/buffer/
Exception Value: a float is required
The value argument is a Unicode string while the format string only accepts a float.
You can also reproduce the same error from the command line:
>>> works_as_expected = yourapp.yourmodel.objects.all().filter(yourdecimalfield__gt=0)
>>> doesnt_work_any_more = yourapp.yourmodel.objects.all().filter(yourdecimalfield__gt=u'0')
Changing the format string from %f to %s fixes the problem in both backends I tested (SQLite + PostgreSQL):
return u"%.*f" % (decimal_places, value) # OLD
return u"%.*s" % (decimal_places, value) # NEW