Easier handling of localize field options in ModelForm
|Reported by:||Henrik Karlsen||Owned by:||Erik Romijn|
|Cc:||Greg Wogan-Browne, mgventura, Simon Charette||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When USE_L10N is set to True in settings, you still has to customize every single form Field to use it in forms. While this is fairly easy with the localize argument to django.forms.fields.Field, it is not easy if you use a ModelForm. In that case, you have to do something similar to this:
class CustomForm(ModelForm): class Meta: model = SomeModel def __init__(self, *args, **kwargs): super(CustomForm, self).__init__(*args, **kwargs) self.fields['some_field'].localize = True
Where some_field in SomeModel for example could be a DecimalField.
I therefore suggest that the USE_L10N setting is used as default value for form Field, as done in the attached patch.
Change History (20)
comment:1 Changed 7 years ago by
|Summary:||Feature request: USE_L10N as default value for form Field → Easier handling of localize field options in ModelForm|
|Triage Stage:||Unreviewed → Accepted|
comment:8 Changed 4 years ago by
|Owner:||changed from nobody to Erik Romijn|
|Status:||new → assigned|