Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ismayil-ismayilov/1a99f009befbe6969db253cc19a0588b to your computer and use it in GitHub Desktop.
Save ismayil-ismayilov/1a99f009befbe6969db253cc19a0588b to your computer and use it in GitHub Desktop.
class CategoryPage(Page):
parent_page_types = ["CoreApp.HomePage"] <- Notice that it is child of Homepage. So breadcrumb in this page is Homepage>CategoryPage
template = "category.html"
description = RichTextField(
null=True,
blank=True,
features=["bold", "italic", "link"],
)
image = models.ForeignKey(
get_image_model(),
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="category_image",
)
content_panels = Page.content_panels + [
FieldPanel("description"),
FieldPanel("image"),
]
def get_context(self, request, *args, **kwargs):
context = super().get_context(request, *args, **kwargs)
breadcrumbs = []
page = self
while page.get_parent() is not None:
if page.is_root():
break
# Note how we do not add self.
page = page.get_parent()
breadcrumbs.append(page)
breadcrumbs.reverse()
context["breadcrumbs"] = breadcrumbs
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment