Installation¶
Install the package from PyPi:
$ pip install django-localized-fields
Add
django.contrib.postgres,psqlextraandlocalized_fieldsto yourINSTALLED_APPS:INSTALLED_APPS = [ ... "django.contrib.postgres", "psqlextra", "localized_fields", ]
Set the database engine to
psqlextra.backend:DATABASES = { "default": { ... "ENGINE": "psqlextra.backend", ], }
Note
Already using a custom back-end? Set
POSTGRES_EXTRA_DB_BACKEND_BASEto your custom back-end. See django-postgres-extra’s documentation for more details: Using a custom database back-end.Set
LANGUAGESandLANGUAGE_CODE:LANGUAGE_CODE = "en" # default language LANGUAGES = ( ("en", "English"), # default language ("ar", "Arabic"), ("ro", "Romanian"), )
Warning
Make sure that the language specified in
LANGUAGE_CODEis the first language in theLANGUAGESlist. Django and many third party packages assume that the default language is the first one in the list.Apply migrations to enable the HStore extension:
$ python manage.py migrate
Note
Migrations might fail to be applied if the PostgreSQL user applying the migration is not a super user. Enabling/creating extensions requires superuser permission. Not a superuser? Ask your database administrator to create the
hstoreextension on your PostgreSQL server manually using the following statement:CREATE EXTENSION IF NOT EXISTS hstore;
Then, fake apply the migration to tell Django that the migration was applied already:
python manage.py migrate localized_fields --fake