Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7069891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:30:03+00:00 2026-05-28T05:30:03+00:00

I have an existing PostgreSQL database that I’m using for a new Django site.

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:30:03+00:00Added an answer on May 28, 2026 at 5:30 am

    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.

    from django.db import models
    from django.core import exceptions
    import re
    
    
    MONEY_REGEX_PATTERN = re.compile('^\$?-?0*(?:\d+(?!,)(?:\.\d{1,2})?|(?:\d{1,3}(?:,\d{3})*(?:\.\d{1,2})?))$')
    
    def MoneyValidator(value):
        """Will validate a string value against a money regular expression"""
        if not MONEY_REGEX_PATTERN.match(value):
            raise exceptions.ValidationError('{v} is not a valid dollar amount'.format(v=value))
    
    
    class MyMoneyField(models.CharField):
    
        """Custom field for handling values from PostgreSQL's money data type"""
    
        def __init__(self, *args, **kwargs):
            kwargs['validators'] = [MoneyValidator]
            kwargs['max_length'] = 20
            super(MyMoneyField, self).__init__(*args, **kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that reads the structure of an existing PostgreSQL 9.1 database,
I have existing Java application that is using Acegi for authentication/authorization. Our new web
I write an application based on an already existing database (postgreSQL) using JPA and
I have an existing database (PostgreSQL in my case), and would like to access
I have an existing database(Postgresql). How can i create models from it? How can
I have and existing database, which I have migrated with SQLAlchemy to a new
I have existing code that uses CMNewProfileSearch to find then iterate over the color
I have existing java code and need to create Design Document based on that.
For whatever reason, I have a lot of clients that have existing data that's
We have an existing WCF service that makes use of wsDualHttpBinding to enable callbacks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.