﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
18471	Add a localization field option in Model Fields.	Serge Spaolonzi	Serge Spaolonzi	"Add a new field option for localization in Model Fields in order to simplify the process of localization.
It happens that activating the localization of a field in the Admin site from a model is a complex task now.
Instead it can be done easily using only a parameter in the Model declaration, in order to archive this I had to modify three lines in the file django.db.models.fields.__init__.py


'''Example:'''
Expected result localization of a decimal field in a model according to the THOUSAND_SEPARATOR setting.

'''Currently it is done this way'''
{{{
import django

class LocalizedModelForm(django.forms.ModelForm):
    def __new__(cls, *args, **kwargs):
        new_class = super(LocalizedModelForm, cls).__new__(cls, *args, **kwargs)
        for field in new_class.base_fields.values():
            if isinstance(field, django.forms.DecimalField):
                field.localize = True
                field.widget.is_localized = True
        return new_class

class FooForm(LocalizedModelForm):
    class Meta:
        model = Foo

django.admin.site.register(Foo, form=FooForm)
}}}


'''After improvement it can be done easily'''
{{{
class Foo(models.Model)
    price = models.DecimalField(verbose_name='Price', max_digits=20, decimal_places=2, localize=True)
}}}


I have the patched code in my Github fork, I will update this ticket with the link to my github code."	New feature	closed	Database layer (models, ORM)	1.4	Normal	wontfix		florian+django@…	Design decision needed	0	0	0	0	0	0
