mirumee / django-prices

Django fields for the prices module
158 stars 52 forks source link

Support for selecting models #8

Closed daGrevis closed 11 years ago

daGrevis commented 11 years ago
from prices import Price
p = Price("1.23")
from core.models import Item
Item.objects.create(name="foo", category_id=1, price=p)
<Item: name: foo, price: Price('1.23', currency=None)>
>>> Item.objects.get(price=p)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/dagrevis/Python/managr/lib/python2.7/site-packages/django/db/models/manager.py", line 143, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/home/dagrevis/Python/managr/lib/python2.7/site-packages/django/db/models/query.py", line 382, in get
    num = len(clone)
  File "/home/dagrevis/Python/managr/lib/python2.7/site-packages/django/db/models/query.py", line 90, in __len__
    self._result_cache = list(self.iterator())
  File "/home/dagrevis/Python/managr/lib/python2.7/site-packages/django/db/models/query.py", line 301, in iterator
    for row in compiler.results_iter():
  File "/home/dagrevis/Python/managr/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 775, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/home/dagrevis/Python/managr/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
    cursor.execute(sql, params)
  File "/home/dagrevis/Python/managr/lib/python2.7/site-packages/django/db/backends/util.py", line 41, in execute
    return self.cursor.execute(sql, params)
  File "/home/dagrevis/Python/managr/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 362, in execute
    return Database.Cursor.execute(self, query, params)
InterfaceError: Error binding parameter 0 - probably unsupported type.

The fix would be to get Decimal in get_prep_value and use it.

What do you think? Thanks!

patrys commented 11 years ago

Would be really great if you could submit at least a unit test. Good find.

daGrevis commented 11 years ago

Okay, no problems. Unfortunately, at the moment I'm at the work.

patrys commented 11 years ago

Should be fixed in 0.2.2.