Opened 9 years ago

Closed 7 years ago

#200 closed enhancement (fixed)

Add a Decimal type and a Currency type

Reported by: Moof <moof@…> Owned by: adrian
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: moof@…, adurdin@…, gary.wilson@…, rushman@… Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Add a DecimalField type that maps between python's Decimal type and mySQL's and PostgreSQL's NUMERIC type. I can't make head nor tail of SQLite's type system, but I assume it has some analogue. It should be possible to define the precision and scale of these types, but they should be optional.

Add a CurrencyField type which is analogous to a DecimalField limited to two decimal places.

Floating point numbers are not good for currency amounts, and I tire of having to convert between an integer number of cents and a string which is in Euro.

Attachments (0)

Change History (16)

comment:1 Changed 9 years ago by Clint Ecker <clintecker@…>

Am I daft, I was under the impression that Sqlite had _no_ typing system to speak of?

comment:2 Changed 9 years ago by rmunn@…

As of SQLite 3, it's slightly more complicated than that, see for details. Basically, it's kind of dynamic-typing-ish: it'll let you store any value in any column, but each value "knows" what type it is (string, integer, real, blob, or null are the five basic types). SQLite doesn't have a NUMERIC datatype, though, so you'd have to fake it using a TEXT datatype and a custom conversion function registered with pysqlite (see

comment:3 Changed 9 years ago by Moof <moof@…>

  • Cc moof@… added

comment:4 Changed 9 years ago by rmunn@…

One disadvantage of using Python's Decimal type is that it would restrict Django to use with Python 2.4. So far Django doesn't require anything newer than 2.3. Perhaps DecimalField and/or CurrencyField could fallback to floats if Decimal isn't available? That would keep the version requirements down to 2.3. They would, of course, still use NUMERIC types in the database itself.

comment:5 Changed 9 years ago by Esaj

It looks like FloatField already uses NUMERIC in PostgreSQL, MySQL and SQLite. Perhaps it should be modified to use a decimal type in Python if possible?

comment:6 Changed 9 years ago by jacob

We're committed to being 2.3-compatible at least for the time being (low barrier to entry and all that), but the idea of using Decimal if it's available is a good one -- patches welcome!

comment:7 Changed 9 years ago by C8E

Note that decimal is perfectly working on 2.3, as stated in

It's a little, single file module. Why don't include it in standard Django distro? It could be eliminated when and if Python 2.3 support will be dropped.

comment:8 Changed 8 years ago by anonymous

Anyone happen to make any progress on support for a currency field?

comment:9 Changed 8 years ago by URL

  • Type enhancement deleted

comment:10 Changed 7 years ago by anonymous

  • Type set to defect

Adding my vote for a Currency type. Crucial for financial applications (one of which I want to convince my management build with Django).

comment:11 Changed 7 years ago by anonymous

  • Type changed from defect to enhancement

comment:12 Changed 7 years ago by adurdin@…

  • Cc adurdin@… added

comment:13 Changed 7 years ago by Gary Wilson <gary.wilson@…>

  • Cc gary.wilson@… added

I could use a Currency type too.

comment:14 Changed 7 years ago by SmileyChris

  • Triage Stage changed from Unreviewed to Design decision needed

This is part of the larger question of what Django is doing with decimal vs float. AFAIK, no decision has been made yet.

comment:15 Changed 7 years ago by Sergey Kirillov <rushman@…>

  • Cc rushman@… added

comment:16 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

The DecimalField was added in [5302].

There are no plans to add a currency field to core at this time, although twe are going to document how to create Field subclasses of your own choosing (for classes that map to single database fields) and add the necessary missing pieces for that. However, it seems to me a currency value is best done as a property that modifies two necessary fields (the value and the currency type), in any case.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.