some more options / features for I18nField

This commit is contained in:
Laura Klünder 2017-11-30 15:26:06 +01:00
parent fa450084dc
commit 6cfd8eb0e3
3 changed files with 19 additions and 9 deletions

View file

@ -50,7 +50,8 @@ class EditorFormBase(ModelForm):
lang=language_info['name_translated'])
new_fields[sub_field_name] = CharField(label=field_title,
required=False,
initial=values[language].strip(), max_length=50)
initial=values[language].strip(),
max_length=model_field.i18n_max_length)
if has_values:
self.i18n_fields.append((model_field, values))
@ -152,6 +153,12 @@ class EditorFormBase(ModelForm):
if not self.cleaned_data.get('geometry'):
raise ValidationError('Missing geometry.')
for field, values in self.i18n_fields:
if not field.blank and not any(values.values()):
raise ValidationError(_('You have to choose a value for {field} in at least one language.').format(
field=field.verbose_name
))
super().clean()
def full_clean(self):