Skip to main content

openexchangerates.org support for django-prices

Project description

openexchangerates.org support for django-prices

codecov PyPI - Version PyPI - Downloads PyPI - Python Version

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.


Crafted with ❤️ by Mirumee Software

hello@mirumee.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_prices_openexchangerates-1.3.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_prices_openexchangerates-1.3.0-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file django_prices_openexchangerates-1.3.0.tar.gz.

File metadata

File hashes

Hashes for django_prices_openexchangerates-1.3.0.tar.gz
Algorithm Hash digest
SHA256 8d44a74edda5b3fc7db666b0bf437eaa5b2e7ca135a8f5d7752ed389a76d54aa
MD5 309f5f838597025ebe91e51669f13c48
BLAKE2b-256 1578c3080f3faa5e64343105119903239070bd64e82fe107d4e129397fa50cdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_prices_openexchangerates-1.3.0.tar.gz:

Publisher: publish.yml on mirumee/django-prices-openexchangerates

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_prices_openexchangerates-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_prices_openexchangerates-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bc3f8f01cba9dcb864c3a0f1ce3ee59b4baa1d8aea3ab273f5e482c5dfc67ae
MD5 865ea9b40f406197d9240c7432df098a
BLAKE2b-256 0eade2d94a195426cc192d9643446b29f4a3d83c712f472a543441624666ccdb

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_prices_openexchangerates-1.3.0-py3-none-any.whl:

Publisher: publish.yml on mirumee/django-prices-openexchangerates

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page