String constructor for LocalizedValue

This allows you to do: LocalizedValue('thing'), which would result in a LocalizedValue looking
like this:

     {'en': 'thing', 'ar': None}
This commit is contained in:
Swen Kooij 2016-12-16 08:30:56 +02:00
parent 2c5090f7a9
commit 3adfe509b2

View File

@ -15,6 +15,9 @@ class LocalizedValue:
different language.
"""
if isinstance(keys, str):
setattr(self, settings.LANGUAGE_CODE, keys)
else:
for lang_code, _ in settings.LANGUAGES:
value = keys.get(lang_code) if keys else None
setattr(self, lang_code, value)