This is about the Format Localization feature that was implemented in Django 1.2.
In order to use this feature, you must add a localize=True
parameter to all your form fields. I am trying to implement this localization in my app but the problem is that I am creating my forms dynamically by using the inlineformset_factory
method that Django provides, so I cannot simply add a new parameter to the form field.
So I tried to enable this feature by default in all models, without needing to add a new parameter for all fields. I created a BaseInlineFormSet subclass and hard-coded 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
That worked only 50%. When submitted, the forms are being validated correctly by Django now (it's accepting commas instead of only dot) but the fields are still being displayed incorrectly.
I guess I could javascript my way out of this problem, but I prefer to avoid doing that.
Any ideas on how to solve this?
Thanks,
Cesar Canassa