What is the best django model field to use to represent a US dollar amount?
The other answers are 100% right but aren't very practical as you'll still have to manually manage output, formatting etc.
I would suggest using django-money:
from djmoney.models.fields import MoneyField
from django.db import models
def SomeModel(models.Model):
some_currency = MoneyField(
decimal_places=2,
default=0,
default_currency='USD',
max_digits=11,
)
Works automatically from templates:
{{ somemodel.some_currency }}
Output:
$123.00
It has a powerful backend via python-money and it's essentially a drop-in replacement for standard decimal fields.
A decimal field is the right choice for the currency value.
It will look something like:
credit = models.DecimalField(max_digits=6, decimal_places=2)