Django

Code

Ticket #200 (closed: fixed)

Opened 3 years ago

Last modified 1 year ago

Add a Decimal type and a Currency type

Reported by: Moof <moof@metamoof.net> Assigned to: adrian
Milestone: Component: Database wrapper
Version: Keywords:
Cc: moof@metamoof.net, adurdin@gmail.com, gary.wilson@gmail.com, rushman@mail.ru Triage Stage: Design decision needed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

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

Change History

07/25/05 19:03:29 changed by Clint Ecker <clintecker@gmail.com>

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

07/25/05 22:02:49 changed by rmunn@pobox.com

As of SQLite 3, it's slightly more complicated than that, see http://www.sqlite.org/datatype3.html 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 http://initd.org/pub/software/pysqlite/doc/usage-guide.html#converting-sqlite-values-to-custom-python-types).

07/26/05 02:59:25 changed by Moof <moof@metamoof.net>

  • cc set to moof@metamoof.net.

07/28/05 09:00:28 changed by rmunn@pobox.com

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.

09/29/05 17:16:37 changed 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?

09/29/05 17:28:19 changed 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!

09/30/05 03:40:27 changed by C8E

Note that decimal is perfectly working on 2.3, as stated in http://www.taniquetil.com.ar/facundo/bdvfiles/get_decimal.html.

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.

05/26/06 08:32:49 changed by anonymous

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

06/12/06 06:37:31 changed by URL

  • type deleted.

01/10/07 17:15:26 changed 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).

01/10/07 17:16:04 changed by anonymous

  • type changed from defect to enhancement.

01/14/07 06:23:31 changed by adurdin@gmail.com

  • cc changed from moof@metamoof.net to moof@metamoof.net, adurdin@gmail.com.

01/14/07 21:49:26 changed by Gary Wilson <gary.wilson@gmail.com>

  • cc changed from moof@metamoof.net, adurdin@gmail.com to moof@metamoof.net, adurdin@gmail.com, gary.wilson@gmail.com.

I could use a Currency type too.

01/17/07 21:28:12 changed by SmileyChris

  • 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.

03/23/07 15:28:05 changed by Sergey Kirillov <rushman@mail.ru>

  • cc changed from moof@metamoof.net, adurdin@gmail.com, gary.wilson@gmail.com to moof@metamoof.net, adurdin@gmail.com, gary.wilson@gmail.com, rushman@mail.ru.

05/20/07 20:48:27 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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/Change #200 (Add a Decimal type and a Currency type)




Change Properties
Action