kopia lustrzana https://github.com/wagtail/wagtail
Add content_panels declarations to i18n duplicate tree example code - fixes #2981
rodzic
d767d547a5
commit
1181a4ea8e
|
@ -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:
|
||||
|
|
Ładowanie…
Reference in New Issue