Improve TranslatedField example

Avoid allocating two variables when only need one.
pull/3162/head
Manuel E. Gutierrez 2016-11-14 16:56:14 -05:00 zatwierdzone przez Matt Westcott
rodzic 2fba07ad8e
commit 5a26e22c0f
2 zmienionych plików z 3 dodań i 6 usunięć

Wyświetl plik

@ -183,6 +183,7 @@ Contributors
* Hammy Goonan
* Thejaswi Puthraya
* Benoît Vogel
* Manuel E. Gutierrez
Translators
===========

Wyświetl plik

@ -166,14 +166,10 @@ Copy this into your project and make sure it's imported in any ``models.py`` fil
self.fr_field = fr_field
def __get__(self, instance, owner):
en = getattr(instance, self.en_field)
fr = getattr(instance, self.fr_field)
if translation.get_language() == 'fr':
return fr
return getattr(instance, self.fr_field)
else:
return en
return getattr(instance, self.en_field)
Then, for each translated field, create an instance of ``TranslatedField`` with a nice name (as this is the name your templates will reference).