django-parlor

Django model translations with even less nasty hacks.
git clone https://git.ce9e.org/django-parlor.git

commit
4616759b88ec02267b853ba776bb11a3db2f5a40
parent
5a96ff555e209e53c1a251eaf1872b1a92a5c35b
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-08-07 07:01
allow to use translation cache on unsaved instances

not sure if this will ever be relevant, but I see no reason to prevent
it

Diffstat

M parlor/models.py 6 +++---

1 files changed, 3 insertions, 3 deletions


diff --git a/parlor/models.py b/parlor/models.py

@@ -8,13 +8,13 @@ class TranslatableModel(models.Model):
    8     8 
    9     9     @property
   10    10     def translation(self):
   11    -1         if not self.pk:
   12    -1             raise self.translations.model.DoesNotExist
   13    -1 
   14    11         translation = self.__dict__.get('_translation')
   15    12         if translation and translation.language_code == get_language():
   16    13             return translation
   17    14 
   -1    15         if not self.pk:
   -1    16             raise self.translations.model.DoesNotExist
   -1    17 
   18    18         translation = self.translations.get(language_code=get_language())
   19    19         self.__dict__['_translation'] = translation
   20    20         return translation