kopia lustrzana https://github.com/wagtail/wagtail
Improve TranslatedField example
Avoid allocating two variables when only need one.pull/3162/head
rodzic
2fba07ad8e
commit
5a26e22c0f
|
@ -183,6 +183,7 @@ Contributors
|
||||||
* Hammy Goonan
|
* Hammy Goonan
|
||||||
* Thejaswi Puthraya
|
* Thejaswi Puthraya
|
||||||
* Benoît Vogel
|
* Benoît Vogel
|
||||||
|
* Manuel E. Gutierrez
|
||||||
|
|
||||||
Translators
|
Translators
|
||||||
===========
|
===========
|
||||||
|
|
|
@ -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
|
self.fr_field = fr_field
|
||||||
|
|
||||||
def __get__(self, instance, owner):
|
def __get__(self, instance, owner):
|
||||||
en = getattr(instance, self.en_field)
|
|
||||||
fr = getattr(instance, self.fr_field)
|
|
||||||
|
|
||||||
if translation.get_language() == 'fr':
|
if translation.get_language() == 'fr':
|
||||||
return fr
|
return getattr(instance, self.fr_field)
|
||||||
else:
|
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).
|
Then, for each translated field, create an instance of ``TranslatedField`` with a nice name (as this is the name your templates will reference).
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue