added new LocalizedCharField, LocalizedTextField and LocalizedFileField fields

This commit is contained in:
seroy
2017-04-12 21:32:30 +03:00
parent 23c6f975d8
commit 817c7e13fe
10 changed files with 364 additions and 14 deletions

View File

@@ -187,7 +187,10 @@ class LocalizedField(HStoreField):
# are any of the language fiels None/empty?
is_all_null = True
for lang_code, _ in settings.LANGUAGES:
if value.get(lang_code):
# NOTE(seroy): use check for None, instead of
# `bool(value.get(lang_code))==True` condition, cause in this way
# we can not save '' value
if value.get(lang_code) is not None:
is_all_null = False
break
@@ -215,7 +218,9 @@ class LocalizedField(HStoreField):
primary_lang_val = getattr(value, settings.LANGUAGE_CODE)
if not primary_lang_val:
# NOTE(seroy): use check for None, instead of `not primary_lang_val`
# condition, cause in this way we can not save '' value
if primary_lang_val is None:
raise IntegrityError(
'null value in column "%s.%s" violates not-null constraint' % (
self.name,