動的な数の画像と説明を含むメイン オブジェクトがあります。
したがって、私は外部キー/タブラインライン コンボを使用しています!
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()
しかし問題は、これらの説明のそれぞれが翻訳可能でなければならないことです。
したがって、管理者は次のようになります。
class InstructionsAdminInline(admin.TabularInline, TranslatableAdmin):
model = InstructionsModel
extra = 3
form = InstructionsMultiAdminForm
list_display = [
'__str__',
]
fieldsets = [
('test', {
'fields': [('title', 'introduction'), 'description', 'mainImage']
}),
]
非常に単純なフォームを使用します(アイデアが不足していることを示すため):
class InstructionsMultiAdminForm(TranslatableModelForm):
class Meta(TranslatableModelForm):
model = InstructionsModel
exclude = ()
def __init__(self, *args, **kwargs):
super(InstructionsMultiAdminForm, self).__init__(*args, **kwargs)
しかし、このエラーは持続します:
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'
(スタック トレースの先頭にある 49 行目は、admin.site.register(InstructionModel, InstructionAdmin)
この行を InstructionAdmin から削除すると:
class InstructionAdmin(TranslatableAdmin):
inlines = [ InstructionsAdminInline ]
エラー停止。
誰かアイデアはありますか?
どうもありがとう!