I have an existing PostgreSQL database that I’m using for a new Django site. When I run:
python manage.py inspectdb
I get several fields which have the PostgreSQL type of “money” that do not convert correctly. To Django’s credit, they at least tell you that they are guessing. 🙂
In the PostgreSQL documentation, they provide the following information for the money type:
Name: money
Storage Size: 8 bytes
Description: currency amount
Range: -92233720368547758.08 to +92233720368547758.07
It seems like to me that this should be a DecimalField in Django.
How have other people handled this? And if you have run into this problem before, did you discover any “gotchas”? Anything that I should be aware of, etc?
Version info:
PostgreSQL 9.1 with Python 2.6.5 and Django 1.3.1
Here is what I did for this problem. I defined a custom field subclassed from CharField and then added a custom validator. Note: I ran into problems with the DecimalField validating correctly in the admin module (I guess you could call this one of the “gotchas” I was asking about!). I have created unit tests for the code and test via the admin pages, and it seems to work fine.