Added a proper deconstruct method to LocalizedValue

This commit is contained in:
Swen Kooij 2016-10-23 16:45:27 +03:00
parent 7e410e857b
commit 69718c376f
2 changed files with 11 additions and 1 deletions

View File

@ -50,6 +50,17 @@ class LocalizedValue:
setattr(self, language, value) setattr(self, language, value)
return self return self
def deconstruct(self) -> dict:
"""Deconstructs this value into a primitive type.
Returns:
A dictionary with all the localized values
contained in this instance.
"""
path = 'localized_fields.fields.LocalizedValue'
return path, [self.__dict__], {}
def __str__(self) -> str: def __str__(self) -> str:
"""Gets the value in the current language, or falls """Gets the value in the current language, or falls
back to the primary language if there's no value back to the primary language if there's no value

View File

@ -36,7 +36,6 @@ class LocalizedFieldWidget(MultiWidget):
result = [] result = []
for lang_code, _ in settings.LANGUAGES: for lang_code, _ in settings.LANGUAGES:
result.append(value.get(lang_code))
if value: if value:
result.append(value.get(lang_code)) result.append(value.get(lang_code))
else: else: