diff --git a/pdp/models.py b/pdp/models.py index 304e27580523ae355219d3fb9bf986b707f5f866..98d52b97f8d06a682ea7e3af063764fadde050f6 100644 --- a/pdp/models.py +++ b/pdp/models.py @@ -12,7 +12,7 @@ from wagtail.documents.blocks import DocumentChooserBlock from wagtail.images.edit_handlers import ImageChooserPanel from wagtailmetadata.models import MetadataPageMixin -from shared.mixins import MatomoMixin +from shared.mixins import MatomoMixin, SharedSubpageMixin from tuning import help from uniweb import models as uniweb @@ -85,7 +85,7 @@ class PdpHomePage( return self -class PdpSubPage(Page, PdpContentMixin, uniweb.SubpageMixin, MetadataPageMixin): +class PdpSubPage(Page, PdpContentMixin, SharedSubpageMixin, MetadataPageMixin): ### FIELDS ### PANELS diff --git a/shared/mixins.py b/shared/mixins.py index a39f712f12cb84c3fde461875f561294fc583e46..5de637065cf56b423d253ef9ed6d631fc52df1c3 100644 --- a/shared/mixins.py +++ b/shared/mixins.py @@ -9,3 +9,15 @@ class MatomoMixin(models.Model): class Meta: abstract = True + + +class SharedSubpageMixin: + """Must be used in class definition before MetadataPageMixin!""" + + @property + def root_page(self): + if not hasattr(self, "_root_page"): + # Vypada to hackove ale lze takto pouzit: dle dokumentace get_ancestors vraci stranky v poradi + # od rootu, tedy domovska stranka je druha v poradi + self._root_page = self.get_ancestors().specific()[1] + return self._root_page