We are talking about the function Localization format , which was implemented in Django 1.2.
To use this function, you must add the localize=True parameter to all fields of the form. I am trying to implement this localization in my application, but the problem is that I dynamically create my forms using the inlineformset_factory method that Django provides, so I cannot just add a new parameter to the form field.
Therefore, I tried to enable this feature by default in all models, without adding a new parameter for all fields. I created a subclass of BaseInlineFormSet and hardcoded the parameter in it.
class MyBaseInlineFormSet(BaseInlineFormSet): def __init__(self, *args, **kwargs): super(MyBaseInlineFormSet, self).__init__(*args, **kwargs) for form in self.forms: for key, field in form.fields.iteritems(): if field.__class__ == forms.DecimalField: form.fields[key].localize = True
This worked for only 50%. When submitting a form, Django is now correctly validated (it accepts commas, not just a period), but the fields are still not displayed correctly.
I think I could javascript get out of this problem, but I prefer to avoid this.
Any ideas on how to solve this?
source share