This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Django Money Model Field

Project Description

Django model field for monetary amounts.


pip install django-moneyfield

Moneyfield requires:

  • Python ==3.3
  • Django ==1.5 (still working on 1.6 compatibility)
  • Money
  • Babel (if you need currency formatting)

Basic usage

from django.db import Models
from moneyfield import MoneyField

class Book(models.Model):
    name = models.CharField(blank=True, max_length=100)
    price = MoneyField(decimal_places=2, max_digits=8)

The field price will be created in the database as two columns: price_amount, and price_currency. You may use any name <fieldname>, resulting in columns <fieldname>_amount and <fieldname>_currency.

CREATE TABLE "myapp_book" (
    "id" integer NOT NULL PRIMARY KEY,
    "name" varchar(100) NOT NULL,
    "price_amount" decimal NOT NULL,
    "price_currency" varchar(3) NOT NULL

The attribute price is only a convenience python descriptor that accepts and returns Money objects, and will be available only when working with a model instance.

>>> book = Book.objects.get(id=1)
>>> book.price
USD 19.99
>>> book.price = Money("9.99", "USD")
>>> book.price
USD 9.99

For any operation using Managers and QuerySets, the amount and the currency must be addressed separately, using price_amount and price_currency in this case. This allows for maximum flexibility and unambiguity.

new_book = Book.objects.create(
    name="The new book",

books_in_usd = Book.objects.filter(price_currency="USD")

cheap_books = Book.objects.filter(price_amount__lt=Decimal('2'))

cheap_books_eur = Book.objects.filter(

Defaults and choices

You can provide separate defaults for the amount and the currency as Decimal and the three letter currency code string, respectively:

class Book(models.Model):
    name = models.CharField(blank=True, max_length=100)
    price = MoneyField(decimal_places=2, max_digits=8,

or a default Money value:

class Book(models.Model):
    name = models.CharField(blank=True, max_length=100)
    price = MoneyField(decimal_places=2, max_digits=8,
                       default=Money("0", "USD"))

You can also set currency choices with currency_choices and a currency default with currency_default:

class Book(models.Model):
        ('EUR', 'EUR'),
        ('USD', 'USD')

    name = models.CharField(blank=True, max_length=100)
    price = MoneyField(decimal_places=2, max_digits=8,

Fixed currency

If you don’t need to handle different currencies but want to benefit from using the Money class instead of just Decimals, you may want to set a fixed currency for your monetary field:

class Book(models.Model):
    name = models.CharField(blank=True, max_length=100)
    price = MoneyField(decimal_places=2, max_digits=12, currency='USD')

In this case, the attribute price will only accept and return Money objects with currency “USD”. The database representation of this field will be price_amount, with no currency column. This is consistent with the multi-currency case, and allows for maximum flexibility while making schema migrations.

MoneyField options

Same as DecimalField: The maximum number of digits allowed in the number. Note that this number must be greater than or equal to decimal_places.
Same as DecimalField: The number of decimal places to store with the number.
Fixed currency for this field. This will omit the creation of a <name>_currency column in the database.
Default Money value for this field (both amount and currency).
Default currency value.
Default amount value.

Regular Django choices iterable, e.g.:

    ('EUR', 'Euros'),
    ('USD', 'US Dollars')


A base model form class MoneyModelForm is included to show the monetary fields as just one field in forms, instead of separate amount and currency fields.

from django.contrib import admin
from moneyfield import MoneyModelForm
from myapp.models import Book

class BookAdmin(admin.ModelAdmin):
    list_display = ['id', 'name', 'price']
    form = MoneyModelForm, BookAdmin)

Using MoneyModelForm is optional. You may also include it in the base classes of your custom model form class.

Using currency choices

Using fixed currency

Using free currency


Contributions are welcome. You can use the regular github mechanisms.

To run the tests, sit on the package root (by and run:

python tests/


django-moneyfield is released under the MIT license, which can be found in the file LICENSE.

Release History

Release History

This version
History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-moneyfield-0.2.1.tar.gz (6.6 kB) Copy SHA256 Checksum SHA256 Source Dec 3, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting