【发布时间】:2019-05-23 03:29:06
【问题描述】:
我最近在我的 Wagtail 网站中创建了一个标签云,但我遇到了一个问题,即出现一些标签(在我的网站中称为“主题”),其中只有私人文章/页面。
到目前为止,我做了这样的事情来获取每个标签中的文章数量,如果没有,则将它们过滤掉:
topics_with_articles = Topic.objects.annotate(num_articles=models.Count("articlepage")).filter(num_articles__gt=0)
filtered_topics = topics_with_articles.order_by("-num_articles").values("name", "slug", "num_articles")
我的模型是这样设置的:
from modelcluster.models import ParentalManyToManyField, ParentalKey
from modelcluster.tags import ClusterTaggableManager
from taggit.models import Tag, TaggedItemBase
@register_snippet
class Topic(Tag):
class Meta:
ordering = ["slug"]
proxy = True
verbose_name = "Topic"
verbose_name_plural = "Topics"
class ArticleTopic(TaggedItemBase):
content_object = ParentalKey("ArticlePage", related_name="article_topics")
class ArticlePage(Page):
topics = ClusterTaggableManager(through="articles.ArticleTopic", blank=True)
我找不到一个简单的解决方案来让它工作,那么我该怎么做呢?
【问题讨论】:
标签: django wagtail django-taggit