2016-12-09 05:54:14 +00:00
|
|
|
from django.utils import translation
|
|
|
|
|
|
|
|
class TranslatedField(object):
|
2018-05-25 13:17:53 +00:00
|
|
|
def __init__(self, de_field, fr_field, en_field):
|
2016-12-09 05:54:14 +00:00
|
|
|
self.de_field = de_field
|
|
|
|
self.fr_field = fr_field
|
2018-05-16 13:08:59 +00:00
|
|
|
self.en_field = en_field
|
2016-12-09 05:54:14 +00:00
|
|
|
|
|
|
|
def __get__(self, instance, owner):
|
|
|
|
if translation.get_language() == 'fr':
|
|
|
|
return getattr(instance, self.fr_field)
|
2018-05-16 13:08:59 +00:00
|
|
|
elif translation.get_language() == 'en':
|
|
|
|
return getattr(instance, self.en_field)
|
2016-12-09 05:54:14 +00:00
|
|
|
else:
|
|
|
|
return getattr(instance, self.de_field)
|