Find Jobs
Hire Freelancers

Fix issue with DecimalField for Django

$30-250 USD

Closed
Posted about 11 years ago

$30-250 USD

Paid on delivery
I'm getting the following error when trying to save a "Subscription" object via Django and DecimalFields: 02/08 09:28:37> Decimal price: 0.00 02/08 09:28:37> Decimal price = None 02/08 09:28:37> Traceback (most recent call last): File "/home/payment/payment/web/api/[login to view URL]", line 170, in create [login to view URL]() File "/home/payment/payment/lib/python2.6/site-packages/django/db/models/[login to view URL]", 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/[login to view URL]", line 483, in save_base values = [(f, f.get_db_prep_save(raw and getattr(self, [login to view URL]) 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/[login to view URL]", 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/[login to view URL]", line 598, in to_python return [login to view URL](value) File "/usr/lib/python2.6/[login to view URL]", 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 #[login to view URL] = str([login to view URL]['subscription_price']) [login to view URL] = Decimal("%.2f" % (float([login to view URL]['subscription_price']))) log('Decimal price: %s' % [login to view URL]) if [login to view URL] == Decimal("0.00"): [login to view URL] = None log('Decimal price = None') Models are as follows (I only pasted the relevant DecimalField fields): class Subscription([login to view URL]): # standard month to month, year to year, etc. pricing. price = [login to view URL](default=0.00, 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 = [login to view URL](default=0.00, 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 = [login to view URL](default=0.00, 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
Project ID: 4225135

About the project

7 proposals
Remote project
Active 11 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
7 freelancers are bidding on average $67 USD for this job
User Avatar
Hi, please check your inbox. Thanks.
$30 USD in 1 day
5.0 (8 reviews)
3.4
3.4
User Avatar
Hi, I would like to fix your issue.
$30 USD in 1 day
4.7 (4 reviews)
3.2
3.2
User Avatar
Hi, I can solve your issue.
$30 USD in 0 day
0.0 (0 reviews)
3.5
3.5
User Avatar
You there?
$30 USD in 1 day
0.0 (0 reviews)
0.0
0.0
User Avatar
Just do what it says: str(float(...)) That is the quick fix. For a proper fix you should be using django-money (djmoney) which basically handles all this for you -- I helped write it. And it also does currency stuff as well.
$250 USD in 1 day
0.0 (0 reviews)
0.0
0.0
User Avatar
hi, let me try this and check you PMB please
$50 USD in 1 day
0.0 (0 reviews)
0.0
0.0
User Avatar
Hi, I'm a Django and python expert. I can help you with this project. For further information, send me a message.
$50 USD in 1 day
0.0 (0 reviews)
0.0
0.0

About the client

Flag of UNITED STATES
Brooklyn, United States
4.8
9
Member since Oct 14, 2003

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.