Created
February 8, 2012 15:57
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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