Installation

  1. Install the package from PyPi:

    $ pip install django-localized-fields
    
  2. Add django.contrib.postgres, psqlextra and localized_fields to your INSTALLED_APPS:

    INSTALLED_APPS = [
        ...
        "django.contrib.postgres",
        "psqlextra",
        "localized_fields",
    ]
    
  3. 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.

  4. Set LANGUAGES and LANGUAGE_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 the LANGUAGES list. Django and many third party packages assume that the default language is the first one in the list.

  5. 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