Installation¶
Install the package from PyPi:
$ pip install django-localized-fields
Add
django.contrib.postgres
,psqlextra
andlocalized_fields
to 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_BASE
to your custom back-end. See django-postgres-extra’s documentation for more details: Using a custom database back-end.Set
LANGUAGES
andLANGUAGE_CODE
:LANGUAGE_CODE = "en" # default language LANGUAGES = ( ("en", "English"), # default language ("ar", "Arabic"), ("ro", "Romanian"), )
Warning
Make sure that the language specified in
LANGUAGE_CODE
is the first language in theLANGUAGES
list. 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
hstore
extension 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