Unverified Commit f812672d authored by Joost Rijneveld's avatar Joost Rijneveld
Browse files

Fix empty verbose_name for MultilingualField

parent 0422f974
......@@ -47,6 +47,18 @@ class TestTranslateMeta(TestCase):
self.assertIn('Text', fr)
self.assertEqual(len({nl, en, fr}), 3)
def test_no_verbose_name(self):
class TestItem3b(models.Model, metaclass=ModelTranslateMeta):
text = MultilingualField(models.TextField)
nl = TestItem3b._meta.get_field('text_nl').verbose_name
en = TestItem3b._meta.get_field('text_en').verbose_name
fr = TestItem3b._meta.get_field('text_fr').verbose_name
self.assertEqual('text (NL)', nl)
self.assertEqual('text (EN)', en)
self.assertEqual('text (FR)', fr)
self.assertEqual(len({nl, en, fr}), 3)
def test_other_kwargs(self):
class TestItem4(models.Model, metaclass=ModelTranslateMeta):
text = MultilingualField(models.CharField, 'Text', max_length=100)
......
......@@ -60,16 +60,15 @@ class ModelTranslateMeta(models.base.ModelBase):
verbose_base = ('args', field.args[0])
else:
verbose_base = ('kwargs', field.kwargs.get('verbose_name',
None))
attr))
for lang in settings.LANGUAGES:
attr_i18n = I18N_FIELD_FORMAT.format(attr, lang[0])
if verbose_base is not None:
verbose_name = '{} ({})'.format(verbose_base[1],
lang[0].upper())
if verbose_base[0] == 'args':
field.args = (verbose_name,) + field.args[1:]
else:
field.kwargs['verbose_name'] = verbose_name
verbose_name = '{} ({})'.format(verbose_base[1],
lang[0].upper())
if verbose_base[0] == 'args':
field.args = (verbose_name,) + field.args[1:]
else:
field.kwargs['verbose_name'] = verbose_name
if attr_i18n in dct:
raise FieldError("Explicit field {} is shadowed "
"by TranslateMeta.".format(attr_i18n))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment