From 5a26e22c0f5f96b441ecfcdf23721f4b48b224bb Mon Sep 17 00:00:00 2001 From: "Manuel E. Gutierrez" <xr09@users.noreply.github.com> Date: Mon, 14 Nov 2016 16:56:14 -0500 Subject: [PATCH] Improve TranslatedField example Avoid allocating two variables when only need one. --- CONTRIBUTORS.rst | 1 + docs/advanced_topics/i18n/index.rst | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 0a0a9df991..2fd3f7cc4a 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -183,6 +183,7 @@ Contributors * Hammy Goonan * Thejaswi Puthraya * BenoƮt Vogel +* Manuel E. Gutierrez Translators =========== diff --git a/docs/advanced_topics/i18n/index.rst b/docs/advanced_topics/i18n/index.rst index 2a7c7e507e..60a67f891c 100644 --- a/docs/advanced_topics/i18n/index.rst +++ b/docs/advanced_topics/i18n/index.rst @@ -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).