Last active
June 19, 2024 16:16
-
-
Save ismayil-ismayilov/1a99f009befbe6969db253cc19a0588b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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