Skip to content

Instantly share code, notes, and snippets.

@mattwilliamson
Created February 8, 2012 15:57
Show Gist options
  • Save mattwilliamson/1770625 to your computer and use it in GitHub Desktop.
Save mattwilliamson/1770625 to your computer and use it in GitHub Desktop.
Snippet to add to django.db.models.base.Model to make decimal fields work with django-nonrel
# Hack by @mattwilliamson because DecimalFields are being set as unicode for some reason with the
# nonrel or maybe mongo updates
def __setattr__(self, name, value):
for field in iter(self._meta.fields):
if field.attname == name:
if field.get_internal_type() == 'DecimalField':
value = field.to_python(value)
break
super(Model, self).__setattr__(name, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment