Django currency conversion

Does Django have a way to do currency conversions? Obviously, the rates change from day to day, but I'm somewhat hoping there is some sort of webservice based converter in the local module: P

There is a snippet here that handles the formatting: http://www.djangosnippets.org/snippets/552/ But I need to localize the values ​​first.

+2


a source to share


2 answers


There are probably more elegant ways to do this, but it works.

currency_in = 'USD'
currency_out = 'NOK'
import urllib2
req = urllib2.urlopen('http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='+currency_in+currency_out+'=X')
result = req.read()
# result = "USDNOK=X",5.9423,"5/3/2010","12:39pm"

      



Then you can split () the result for the modifier.

+5


a source


You can use the django-money currency conversion app in Django based projects.

It works with different speed sources and provides an interface to perform conversions and localize money:



>>> # After app setup & adding rates to the DB
>>> from djmoney.money import Money
>>> from djmoney.contrib.exchange.models import convert_money
>>> value = Money(100, 'EUR')
>>> converted = convert_money(value, 'USD')
>>> converted
<Money: 122.8184375038380800 USD>
>>> str(converted)
US$122.82

      

The formats are easily customizable, you can find the documentation on the project page.

0


a source







All Articles