mirror of
https://github.com/Hopiu/django-modeltranslation.git
synced 2026-05-12 15:23:09 +00:00
Handled nested lists to display multiple fields on same line by flatting them.
This commit is contained in:
parent
c5836ce20f
commit
ee380ec7b7
2 changed files with 27 additions and 2 deletions
|
|
@ -101,8 +101,20 @@ class TranslationBaseModelAdmin(BaseModelAdmin):
|
|||
['title_de', 'title_en']
|
||||
>>> self.replace_orig_field(['title', 'url'])
|
||||
['title_de', 'title_en', 'url']
|
||||
|
||||
Note that grouped fields are flattened. We do this because:
|
||||
|
||||
1. They are hard to handle in the jquery-ui tabs implementation
|
||||
2. They don't scale well with more than a few languages
|
||||
3. It's better than not handling them at all (okay that's weak)
|
||||
|
||||
>>> print self.trans_opts.fields
|
||||
(('title', 'url'), 'email')
|
||||
>>> get_translation_fields(self.trans_opts.fields[0])
|
||||
['title_de', 'title_en', 'url_de', 'url_en', 'email_de', 'email_en']
|
||||
>>> self.replace_orig_field((('title', 'url'), 'email', 'text'))
|
||||
['title_de', 'title_en', 'url_de', 'url_en', 'email_de', 'email_en', 'text']
|
||||
"""
|
||||
# TODO: Handle nested lists to display multiple fields on same line.
|
||||
if option:
|
||||
option_new = list(option)
|
||||
for opt in option:
|
||||
|
|
@ -110,11 +122,14 @@ class TranslationBaseModelAdmin(BaseModelAdmin):
|
|||
index = option_new.index(opt)
|
||||
translation_fields = get_translation_fields(opt)
|
||||
option_new[index:index + 1] = translation_fields
|
||||
elif isinstance(opt, (tuple, list)) and (
|
||||
[o for o in opt if o in self.trans_opts.fields]):
|
||||
index = option_new.index(opt)
|
||||
option_new[index:index + 1] = self.replace_orig_field(opt)
|
||||
option = option_new
|
||||
return option
|
||||
|
||||
def _patch_fieldsets(self, fieldsets):
|
||||
# TODO: Handle nested lists to display multiple fields on same line.
|
||||
if fieldsets:
|
||||
fieldsets_new = list(fieldsets)
|
||||
for (name, dct) in fieldsets:
|
||||
|
|
|
|||
|
|
@ -1424,6 +1424,16 @@ class TranslationAdminTest(ModeltranslationTestBase):
|
|||
self.assertEqual(
|
||||
ma.get_form(request).base_fields.keys(), ['title_de', 'title_en'])
|
||||
|
||||
# Using grouped fields.
|
||||
class TestModelAdmin(TranslationAdmin):
|
||||
fields = (('title', 'url'), 'email',)
|
||||
|
||||
ma = TestModelAdmin(TestModel, self.site)
|
||||
# Note: Current implementation flattens the nested fields
|
||||
self.assertEqual(
|
||||
ma.get_form(request).base_fields.keys(),
|
||||
['title_de', 'title_en', 'url_de', 'url_en', 'email_de', 'email_en'])
|
||||
|
||||
def test_field_arguments_restricted_on_custom_form(self):
|
||||
# Using `fields`.
|
||||
class TestModelForm(forms.ModelForm):
|
||||
|
|
|
|||
Loading…
Reference in a new issue