I'm having a main object that contain a dynamic numbers of images and descriptions.

Thus, I'm using the Foreign Key / tabularinline combo!

class InstructionsModel(TranslatableModel):
  instruction = models.ForeignKey(InstructionModel, related_name='instructions_plural_project')
  mainImage = FilerImageField(verbose_name=('Marker image'), 
                            blank=True, null=True, 
                            on_delete=models.SET_NULL)
  translations = TranslatedFields(
    title=models.CharField(_('Instruction title'), max_length=255),
    introduction=RichTextField(_('Instruction introduction or subtitle'), default='', blank=True),
    description=RichTextField(_('Instruction description'), default='', blank=True),
  )

  _metadata = {
    'title': 'get_title',
  }

  def get_title(self):
    title = self.safe_translation_getter('meta_title', any_language=True)
    if not title:
        title = self.safe_translation_getter('title', any_language=True)
    return title

  def __str__(self):
    title = self.safe_translation_getter('title', any_language=True)
    return title if title is not None else '(not translated)'

  def save(self, *args, **kwargs):
    super(InstructionsModel, self).save(*args, **kwargs)
    main_lang = self.get_current_language()
    for lang in self.get_available_languages():
        self.set_current_language(lang)
    self.set_current_language(main_lang)
    self.save_translations()

But the problem is that each of those descriptions has to be translatable.

thus the admin looks like this:

class InstructionsAdminInline(admin.TabularInline, TranslatableAdmin):
    model = InstructionsModel
    extra = 3
    form = InstructionsMultiAdminForm

    list_display = [
        '__str__',
    ]

    fieldsets = [
        ('test', {
            'fields': [('title', 'introduction'), 'description', 'mainImage']
        }),
    ]

with a very simple form (to show you that I'm running out of ideas on it):

class InstructionsMultiAdminForm(TranslatableModelForm):
    class Meta(TranslatableModelForm):
        model = InstructionsModel
        exclude = ()

    def __init__(self, *args, **kwargs):
        super(InstructionsMultiAdminForm, self).__init__(*args, **kwargs)

But this error persist:

 File "/Users/JayCee/education-proj/homeroom/homeroom/django_instructions/admin.py", line 49, in <module>
    admin.site.register(InstructionModel, InstructionAdmin)
  File "/Users/JayCee/education-proj/homeroom/lib/python3.5/site-packages/django/contrib/admin/sites.py", line 109, in register
    system_check_errors.extend(admin_obj.check())
  File "/Users/JayCee/education-proj/homeroom/lib/python3.5/site-packages/django/contrib/admin/options.py", line 113, in check
    return self.checks_class().check(self, **kwargs)
  File "/Users/JayCee/education-proj/homeroom/lib/python3.5/site-packages/django/contrib/admin/checks.py", line 498, in check
    errors.extend(self._check_inlines(admin_obj))
  File "/Users/JayCee/education-proj/homeroom/lib/python3.5/site-packages/django/contrib/admin/checks.py", line 536, in _check_inlines
    for index, item in enumerate(obj.inlines)
  File "/Users/JayCee/education-proj/homeroom/lib/python3.5/site-packages/django/contrib/admin/checks.py", line 536, in <listcomp>
    for index, item in enumerate(obj.inlines)
  File "/Users/JayCee/education-proj/homeroom/lib/python3.5/site-packages/django/contrib/admin/checks.py", line 567, in _check_inlines_item
    return inline(model, obj.admin_site).check()
  File "/Users/JayCee/education-proj/homeroom/lib/python3.5/site-packages/django/contrib/admin/options.py", line 1765, in __init__
    super(InlineModelAdmin, self).__init__()
TypeError: __init__() missing 2 required positional arguments: 'model' and 'admin_site'

(the line 49 at the beginning of the stack trace refer to the admin.site.register(InstructionModel, InstructionAdmin)

If I remove this line from InstructionAdmin:

class InstructionAdmin(TranslatableAdmin):
    inlines = [ InstructionsAdminInline ]

The error stop.

Any idea anyone?

Many thanks!

1

There are 1 best solutions below

0
On

The problem came from the translation. There is a specific class from django-parler for this:

TranslatableTabularInline

Once it's done no more errors.

from parler.admin import TranslatableAdmin, TranslatableTabularInline

class InstructionsAdminInline(TranslatableTabularInline):
    model = InstructionsModel