开发者

Django form floatfield separator

开发者 https://www.devze.com 2022-12-17 19:33 出处:网络
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.

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)
0

精彩评论

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

关注公众号