Note that there are some explanatory texts on larger screens.

plurals
  1. POLocalization of Django application only applies to forms.py and not to models.py
    primarykey
    data
    text
    <p>I have a problem when trying to localize my application. It is available in two languages: english and german. The problem appears when the browser has the language set english(United States) and in my settings file is set to 'de' and vice-versa. Some fields appear in english, others in german. My model contains CharField, DecimalField and DateField field types.</p> <p><strong>models.py:</strong> </p> <pre><code>from django.db import models from django.utils.translation import ugettext as _ class Test(models.Model): test_number = models.CharField(_('Test number'), max_length=20) test_date = models.DateField() test_price = models.DecimalField(_('Test price'), max_digits=16, decimal_places=2, null=True, blank=True) </code></pre> <p><strong>forms.py:</strong> </p> <pre><code>class TestForm(ModelForm): test_date = forms.DateField(label=_('Booking date'), widget=AdminDateWidget) </code></pre> <p><strong>settings.py</strong> </p> <pre><code>USE_L10N = True USE_I18N = True TIME_ZONE = 'Europe/Berlin' LANGUAGE_CODE = 'de' TEMPLATE_CONTEXT_PROCESSORS = ( "django.core.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.request", ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.core.files.uploadhandler.MemoryFileUploadHandler', 'django.core.files.uploadhandler.TemporaryFileUploadHandler', 'django.middleware.transaction.TransactionMiddleware', 'pagination.middleware.PaginationMiddleware', ) </code></pre> <p>English is the language set the browser.The labels of the fields test_number and test_price appear in german and the label of test_date in english. If I remove _('Test number') from models.py and added it as label attribute in forms.py it works. Isn't it another way of doing this? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload