开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜