Code Monkey home page Code Monkey logo

django-extras's People

Contributors

josiahseaman avatar movermeyer avatar timsavage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-extras's Issues

Validation error with MoneyField

I have the following field in my Django app model:

    total_amount = models.MoneyField("total amount including GST", max_digits=9, decimal_places=2, default=0)

When I try and add data using this field, I get an "Invalid literal for Decimal: ''" error with the following traceback:

Environment:


Request Method: POST
Request URL: http://robs-tosh-t130:8000/admin/accounts/account/add/

Django Version: 1.5
Python Version: 2.7.4
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'django_extras',
 'accounts')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/core/handlers/base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/contrib/admin/options.py" in wrapper
  372.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/views/decorators/cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/contrib/admin/sites.py" in inner
  202.             return view(request, *args, **kwargs)
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/utils/decorators.py" in _wrapper
  25.             return bound_func(*args, **kwargs)
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/utils/decorators.py" in bound_func
  21.                 return func(self, *args2, **kwargs2)
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/db/transaction.py" in inner
  223.                 return func(*args, **kwargs)
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/contrib/admin/options.py" in add_view
  989.             if form.is_valid():
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/forms/forms.py" in is_valid
  126.         return self.is_bound and not bool(self.errors)
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/forms/forms.py" in _get_errors
  117.             self.full_clean()
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/forms/forms.py" in full_clean
  274.         self._post_clean()
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/forms/models.py" in _post_clean
  332.             self.instance.clean_fields(exclude=exclude)
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/db/models/base.py" in clean_fields
  946.                 setattr(self, f.attname, f.clean(raw_value, self))
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/db/models/fields/__init__.py" in clean
  212.         self.validate(value, model_instance)
File "/dev/simple-bas/simple_bas/eggs/Django-1.5-py2.7.egg/django/db/models/fields/__init__.py" in validate
  202.         if not self.blank and value in validators.EMPTY_VALUES:
File "/dev/simple-bas/simple_bas/eggs/django_extras-0.2.8-py2.7.egg/django_extras/core/types.py" in __eq__
  133.         return self._amount == decimal.Decimal(str(other))
File "/usr/lib/python2.7/decimal.py" in __new__
  548.                                 "Invalid literal for Decimal: %r" % value)
File "/usr/lib/python2.7/decimal.py" in _raise_error
  3872.         raise error(explanation)

Exception Type: InvalidOperation at /admin/accounts/account/add/
Exception Value: Invalid literal for Decimal: ''

As far as I can tell, the code is trying to validate my data (which was 120.00) against an empty string (?) in validators.EMPTY_VALUES and failing because that's not a Decimal.

MoneyField data not saved to DB

I have the following field in my Django app model:

 total_amount = models.MoneyField("total amount including GST", max_digits=9, decimal_places=2, default=0)

When I add a new record via the web interface, valid data entered into this field is not persisted to the database (PostgreSQL in my case).

After adding a record and checking the DB (using the pgAdmin III tool), I then updated my total_amount field via this tool and saved it. After this, when I edited that record via the Django Admin web interface, the value I put directly into the DB was displayed in my total_amount field on the web edit form. However, when I saved this web form without making any changes to the data, my MoneyField data was again wiped from the database record.

It seems that a null value is being consistently written to the database when a MoneyField value is being saved.

Instructions

What are the installation/usage instructions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.