Django-EasyMoney
An easy to use money field for Django. Handles type conversions and arithmetic seamlessly.
Requirements
Python 2.7 and 3.3+, Django 1.6+.
Installation
pip install django-easymoney
Overview
from django.db import models
from easymoney import MoneyField
class MyModel(models.Model):
price = MoneyField(default=3.14)
other_price = MoneyField(default=1)
obj = MyModel()
print obj.price # -> $3.14
# Money arithmetic
obj.price + obj.other_price # $4.14
# Mix with ints and floats
obj.price + 1 # $4.14
obj.price + 0.2 # $3.34
# No partial cents or crazy floats
obj.price / 3 # $1.05
Settings
A primary use of easymoney is global currency defined in settings with global formatting and precision. Here is how you do that:
# These are default settings, code and locales refer to ones used in babel library
CURRENCY_CODE = 'USD'
CURRENCY_LOCALE = 'en_US'
CURRENCY_DECIMAL_PLACES = 2
# This is optional, for cases when you want to use some fake currency
CURRENCY_FORMAT = '# points'
Several currencies
One money field can’t store different currencies, however, you can create different money classes and model fields for them:
from easymoney import Money, MoneyField
class GameMoney(Money):
# CODE = '...'
# LOCALE = '...'
DECIMAL_PLACES = 0
FORMAT = '# points'
class GameMoneyField(MoneyField):
MONEY_CLASS = GameMoney
Metadata
Release files for django-easymoney 0.7.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-easymoney-0.7.2.tar.gz | 6.0 kB | Without provenance | Details |
Release files / django-easymoney-0.7.2.tar.gz
| Download URL | django-easymoney-0.7.2.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7654652f1ab56d08e19fc29f1e01cf525261a5b10c61f03973ec85b029e66b54
|
|
BLAKE2b-256 checksum How to use checksums |
a69e78ba506e396fa3da4524295c39247542331bcd1926b49074db410f7b98ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-easymoney 0.7.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.