def get_category_tag_cloud(): from techblog.services.articles import ArticleService from techblog.services.categories import CategoryService cats = CategoryService.get_categories_with_count() for category in cats: article_ids = ArticleService.get_article_ids_by_category(category) category.tags = list(TagService.get_filtered_tag_cloud([a.id for a in article_ids])) if not category.tags: category.empty = True return cats