diff --git a/website/blog/models.py b/website/blog/models.py index 5615841..4e41a86 100644 --- a/website/blog/models.py +++ b/website/blog/models.py @@ -7,6 +7,7 @@ from django.utils import timezone from django.utils.functional import cached_property from modelcluster.fields import ParentalManyToManyField from wagtail.admin.panels import FieldPanel +from wagtail.models import PageQuerySet from wagtail.search import index from wagtailautocomplete.edit_handlers import AutocompletePanel @@ -61,6 +62,19 @@ class BlogPostPage(BaseContentPage): def tag_list_page_url(self) -> Optional[str]: return SingletonPageCache.get_url(BlogPostTagListPage) + @cached_property + def tags_list(self) -> models.QuerySet: + """ + Use this to get a page's tags. + """ + tags = self.tags.order_by("slug") + + # In drafts, `django-modelcluster` doesn't support these filters + if isinstance(tags, PageQuerySet): + return tags.public().live() + + return tags + @cached_property def blog_post_list_page_url(self) -> Optional[str]: return SingletonPageCache.get_url(BlogPostListPage) diff --git a/website/common/templates/common/content-details.html b/website/common/templates/common/content-details.html index 4f84a6f..f57a57b 100644 --- a/website/common/templates/common/content-details.html +++ b/website/common/templates/common/content-details.html @@ -20,14 +20,14 @@ {% endif %} - {% if page.tags.public.live.all %} + {% if page.tags_list %}