Skip to main content

Django model translations with even less nasty hacks.

Project description

django-parlor

Django model translations with even less nasty hacks.

Installation

pip install django-parlor

Usage

from django.contrib import admin
from django.db import models

from parlor.admin import TranslatableAdmin
from parlor.models import TranslatableModel


class MyModel(TranslatableModel):
    ...


class MyModelTranslation(models.Model):
    parent = MyModel.get_parent_field()
    language_code = MyModel.get_language_field()

    label = models.CharField(max_length=32)
    ...

    class Meta:
        unique_together = [('parent', 'language_code')]


admin.site.register(MyModel, TranslatableAdmin)

animal = MyModel.objects.create()
animal.translations.create(language_code='en', label='Frog')
animal.translations.create(language_code='de', label='Frosch')
print(animal.label)

Status

Right now this is more of a proof-of-concept. If people are interested in this library it could certainly be expanded.

Relation to django-parler

Standing on the Shoulders of Giants

There are two popular libraries for model translation in Django: django-modeltranslation and django-parler. The former adds additional columns to the same table while the latter adds a new table for each translatable model. Both of these libraries use a lot of magic which makes them easy to use, but also leads to some hard-to-debug edge cases.

There is also django-translated-fields, which uses the same basic approach as django-modeltranslation, but with much less magic (and much less lines of code).

Here I try to do something similar for django-parler, which has been unmaintained for some time now.

Migration

If you want to migrate from django-parler to django-parlor, you need to replace all instances of parler.TranslatedFields by explicit translation models as described above. Note that the parent field is called master in django-parler.

To keep using the same data, you will also need to set Meta.db_table to the name generated by django-parler (typically myapp_mymodel_translation).

Finally you should run manage.py makemigrations. The generated migrations will only contain minor changes though.

Conceptual differences

  • With django-parlor, the translation model must be created explicitly.
  • In the admin UI, django-parlor uses a stock inline instead of a custom tabbed interface.
  • django-parlor only provides basic attribute access while django-parler provides a lot more features.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_parlor-0.0.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_parlor-0.0.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file django_parlor-0.0.2.tar.gz.

File metadata

  • Download URL: django_parlor-0.0.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_parlor-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b3bd35113906dd7401c25a4bf50fdde2774bb2043c9f573ae39454ad72877c26
MD5 9740a34ad44d71d46aa9e7f7e1583df6
BLAKE2b-256 6ecdc14537b51fc238d8627254059f2903e538939e6cb6af168896df2119404d

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_parlor-0.0.2.tar.gz:

Publisher: main.yml on xi/django-parlor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_parlor-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: django_parlor-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_parlor-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 909a11dddcc30e1cb7ae3dbfc82f62bcc909744e1beaa61a1ab4562ff703fce8
MD5 2b86a0d0d623a270cdb7f842f59be127
BLAKE2b-256 acd61f9c49b39e26b8d24578e46d1112b27d2095dc39f596c87422e1c111f8d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_parlor-0.0.2-py3-none-any.whl:

Publisher: main.yml on xi/django-parlor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page