@@ -0,0 +1,1023 @@
+# -*- coding: utf-8 -*-%0Afrom __future__ import unicode_literals%0A%0Afrom django.db import migrations%0A%0A%0Adef add_language_relation(apps, schema_editor):%0A    from molo.core.models import SiteLanguage, LanguageRelation%0A    from wagtail.wagtailcore.models import Page%0A%0A    if not (SiteLanguage.objects.filter(is_main_language=True)).exists():%0A        from molo.core.models import LanguagePage%0A        current_language = LanguagePage.objects.live().first()%0A%0A        if current_language:%0A            main_lang = SiteLanguage.objects.create(%0A                locale=current_language.code)%0A            for p in Page.objects.all().descendant_of(current_language):%0A                LanguageRelation.objects.create(page=p, language=main_lang)%0A%0A%0Aclass Migration(migrations.Migration):%0A%0A    dependencies = %5B%0A        ('tuneme', '0001_initial'),%0A        ('polls', '0025_create_polls_index_pages'),%0A        ('yourwords', '0006_create_your_words_index_pages'),%0A    %5D%0A%0A    operations = %5B%0A        migrations.RunPython(add_language_relation),%0A    %5D%0A

Add language relation to existing pages