Django form floatfield separator
I have a form floatfield. What is the best way to change the default separator from '.' to ','? I tried to set the DECIMAL_SEPARATOR in the settings to ',' but this doesn't help. Is there a way to configure this or do I have to overwrite the clean method of t开发者_运维百科he floatfield? Thank you!
FloatField
does not support i18n; you'll have to write your own.
Since django 1.2, FloatField
has a localize
member. You can set it to True. The coma separator will be accepted if you local is french for example.
for example:
class MyForm(ModelForm):
def __init__(self, *args, **kwargs):
super(MyForm).__init__(self, *args, **kwargs)
self.fields['my_float'].localize = True
or
MyForm(Form):
my_float = forms.FloatField(localize=True)
精彩评论