openexchangerates.org support for django-prices
Project description
openexchangerates.org support for django-prices
from prices import Money
from django_prices_openexchangerates import exchange_currency
converted_price = exchange_currency(Money(10, currency='USD'), 'EUR')
print(converted_price)
# Money('8.84040', currency='EUR')
It will also create additional steps if it cannot convert directly:
from prices import Money
from django_prices_openexchangerates import exchange_currency
converted_price = exchange_currency(Money(10, currency='GBP'), 'EUR')
print(converted_price)
# Money('13.31313588062401085236264978', currency='EUR')
The exchange_currency
supports Money
, TaxedMoney
, MoneyRange
and TaxedMoneyRange
.
Template filters can be used with django-prices
to convert currency, round amounts and display localized amounts in templates:
{% load prices_i18n %}
{% load prices_multicurrency %}
<p>Price: {{ foo.price.gross|in_currency:'USD'|amount }} ({{ foo.price.net|in_currency:'USD'|amount }} + {{ foo.price.tax|in_currency:'USD'|amount }} tax)</p>
Installation
First install the package:
pip install django-prices-openexchangerates
Then add 'django_prices_openexchangerates'
to your INSTALLED_APPS
.
Set following settings in your project's settings:
-
OPENEXCHANGERATES_API_KEY
-
OPENEXCHANGERATES_BASE_CURRENCY
(defaults to'USD'
, only premium accounts support other bases)
Use your admin console to create ConversionRate
objects for each currency that you want to support.
Updating exchange rates
Fetch current rates from API with ./manage.py update_exchange_rates
Schedule this task in cron job or in celery, to be always up to date with exchange rates
You can use --all
flag in above command, to create exchange rates automatically for all available currencies.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-prices-openexchangerates-1.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 183cc2b6c15da7555d36b03634fef6c73c80e692a9f63ff0bfc1443f57f55740 |
|
MD5 | b04a9cc5695018714a5851ae61e5e1e5 |
|
BLAKE2b-256 | f658a213125fae113e514846d4d786d202840bed6626ca0bc727ebe782a51ac2 |
Hashes for django_prices_openexchangerates-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2daff7ae82632ca4fd23e1b5328d9520b9d6a9f75e652f93ea8c8935d94f2baf |
|
MD5 | 88fc1e72abfd9ed29a7a2312eb5bb549 |
|
BLAKE2b-256 | d9ad34ddcbb01ce6948c6afb4ff9ac7ffe54de30ada343515e852be408d4856e |