Django: use get_prep_value() to remove dollar signs?
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(valu开发者_开发百科e.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?
You should do this in the form field, since it's an issue that will only happen with form input.
精彩评论