diff --git a/wagtail_modeltranslation/apps.py b/wagtail_modeltranslation/apps.py index f77efc0..a21d273 100644 --- a/wagtail_modeltranslation/apps.py +++ b/wagtail_modeltranslation/apps.py @@ -10,9 +10,22 @@ class ModeltranslationConfig(AppConfig): def ready(self): from django.conf import settings + from modeltranslation import settings as mt_settings + # Add Wagtail defined fields as modeltranslation custom fields - setattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', getattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', ()) + ( - 'StreamField', 'RichTextField')) + wagtail_fields = ( + 'StreamField', + 'RichTextField', + ) + + # update both the standard settings and the modeltranslation settings, + # as we cannot guarantee the load order, and so django_modeltranslation + # may bootstrap itself either before, or after, our ready() gets called. + custom_fields = getattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', tuple()) + setattr(settings, 'MODELTRANSLATION_CUSTOM_FIELDS', tuple(set(custom_fields + wagtail_fields))) + + mt_custom_fields = getattr(mt_settings, 'CUSTOM_FIELDS', tuple()) + setattr(mt_settings, 'CUSTOM_FIELDS', tuple(set(mt_custom_fields + wagtail_fields))) from modeltranslation.models import handle_translation_registrations handle_translation_registrations()