+ related_tags = Tag.objects.usage_for_model(Picture, counts=True)
+ related_tags = sorted(related_tags, key=lambda t: -t.count)
+ suggestion_categories = Counter()
+ suggestions = []
+ for t in related_tags:
+ if suggestion_categories[t.category] < 3:
+ suggestion_categories[t.category] += 1
+ suggestions.append(t)
+ if sum(suggestion_categories.values()) == 10:
+ break