Closed

Fix issue with DecimalField for Django

This project received 7 bids from talented freelancers with an average bid price of $67 USD.

Get free quotes for a project like this
Employer working
Skills Required
Project Budget
N/A
Total Bids
7
Project Description

I'm getting the following error when trying to save a "Subscription" object via Django and DecimalFields:

02/08 09:28:37> Decimal price: [url removed, login to view]
02/08 09:28:37> Decimal price = None
02/08 09:28:37> Traceback (most recent call last):
File "/home/payment/payment/web/api/[url removed, login to view]", line 170, in create
[url removed, login to view]()
File "/home/payment/payment/lib/python2.6/site-packages/django/db/models/[url removed, login to view]", line 410, in save
self.save_base(force_insert=force_insert, force_update=force_update)
File "/home/payment/payment/lib/python2.6/site-packages/django/db/models/[url removed, login to view]", line 483, in save_base
values = [(f, f.get_db_prep_save(raw and getattr(self, [url removed, login to view]) or f.pre_save(self, True))) for f in meta.local_fields if not isinstance(f, AutoField)]
File "/home/payment/payment/lib/python2.6/site-packages/django/db/models/fields/[url removed, login to view]", line 624, in get_db_prep_save
return connection.ops.value_to_db_decimal(self.to_python(value),
File "/home/payment/payment/lib/python2.6/site-packages/django/db/models/fields/[url removed, login to view]", line 598, in to_python
return [url removed, login to view](value)
File "/usr/lib/python2.6/[url removed, login to view]", line 649, in __new__
"First convert the float to a string")
TypeError: Cannot convert float to Decimal. First convert the float to a string

Here is the code:

# standard pricing
#[url removed, login to view] = str([url removed, login to view]['subscription_price'])
[url removed, login to view] = Decimal("%.2f" % (float([url removed, login to view]['subscription_price'])))
log('Decimal price: %s' % [url removed, login to view])

if [url removed, login to view] == Decimal("[url removed, login to view]"):
[url removed, login to view] = None
log('Decimal price = None')

Models are as follows (I only pasted the relevant DecimalField fields):

class Subscription([url removed, login to view]):
# standard month to month, year to year, etc. pricing.
price = [url removed, login to view](default=[url removed, login to view], max_digits=10, decimal_places=2, null=True, blank=True) # Price of the item we auto-create every billing cycle (0 if None)

# price for extra users
price_per_extra_user = [url removed, login to view](default=[url removed, login to view], max_digits=10, decimal_places=2, null=True, blank=True, help_text="The price for extra users.")

# first billing interval
first_price_per_num_dmy = [url removed, login to view](default=[url removed, login to view], max_digits=10, decimal_places=2, null=True, blank=True, help_text="The first payment's price per user")


Please let me know if you know of a quick fix. I can provide SVN source code access... but most programmers shoul

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online