From 1181a4ea8e0ab03bb1a7432c072c8d20a4008229 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Tue, 6 Sep 2016 10:44:33 +0100 Subject: [PATCH] Add content_panels declarations to i18n duplicate tree example code - fixes #2981 --- docs/advanced_topics/i18n/duplicate_tree.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/advanced_topics/i18n/duplicate_tree.rst b/docs/advanced_topics/i18n/duplicate_tree.rst index 010f18e91..2ceb89dfb 100644 --- a/docs/advanced_topics/i18n/duplicate_tree.rst +++ b/docs/advanced_topics/i18n/duplicate_tree.rst @@ -58,12 +58,21 @@ Here's an example of how this could be implemented (with English as the main lan .. code-block:: python + from wagtail.wagtailcore.models import Page + from wagtail.wagtailadmin.edit_handlers import MultiFieldPanel, PageChooserPanel + + class TranslatablePageMixin(models.Model): # One link for each alternative language # These should only be used on the main language page (english) french_link = models.ForeignKey(Page, null=True, on_delete=models.SET_NULL, blank=True, related_name='+') spanish_link = models.ForeignKey(Page, null=True, on_delete=models.SET_NULL, blank=True, related_name='+') + panels = [ + PageChooserPanel('french_link'), + PageChooserPanel('spanish_link'), + ] + def get_language(self): """ This returns the language code for this page. @@ -121,10 +130,18 @@ Here's an example of how this could be implemented (with English as the main lan class AboutPage(Page, TranslatablePageMixin): ... + content_panels = [ + ... + MultiFieldPanel(TranslatablePageMixin.panels, 'Language links') + ] class ContactPage(Page, TranslatablePageMixin): ... + content_panels = [ + ... + MultiFieldPanel(TranslatablePageMixin.panels, 'Language links') + ] You can make use of these methods in your template by doing: