Add content_panels declarations to i18n duplicate tree example code - fixes #2981

pull/2982/head
Matt Westcott 2016-09-06 10:44:33 +01:00
rodzic d767d547a5
commit 1181a4ea8e
1 zmienionych plików z 17 dodań i 0 usunięć

Wyświetl plik

@ -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: