views:

32

answers:

1

Is it advisable to use get_prep_value() in my Django Field subclass to do this (my custom field is a sub-class of DecimalField):

def get_prep_value(self, value):
    from decimal import Decimal
    value = Decimal(value.replace('$', ''))
    return super(MyCustomField, self).get_prep_value()

Does this pose a problem with django's ModelForm validation (ie, will ModelForm's validation see the decimal field subclass and not allow a $ to ever reach the model layer? Should I make a custom form field and set it as the default in this model field? Is there other issues?

A: 

You should do this in the form field, since it's an issue that will only happen with form input.

Daniel Roseman
That would be true normally, but I'm building an API that won't use forms so I need the lowest level in the stack to catch it.
orokusaki