Add automatic tag collections

This commit is contained in:
rucki
2026-08-27 16:48:56 +02:00
parent 2bcd9d901a
commit 682f5f7442
11 changed files with 197 additions and 56 deletions
+7 -2
View File
@@ -35,7 +35,7 @@ def without_markdown_code(text):
def delete_unused_tags(tags=None):
"""Delete tags that are no longer used by items or tag-based features."""
candidates = Tag.objects.all() if tags is None else Tag.objects.filter(pk__in=[tag.pk for tag in tags])
candidates.filter(items__isnull=True, kanbans__isnull=True, api_keys__isnull=True, collections__isnull=True).exclude(
candidates.filter(items__isnull=True, kanbans__isnull=True, api_keys__isnull=True, tag_collections__isnull=True).exclude(
name__in=Team.objects.values_list('slug', flat=True),
).delete()
@@ -196,12 +196,17 @@ class Kanban(models.Model):
class Collection(models.Model):
class Mode(models.TextChoices):
MANUAL = 'manual', _('Manual collection')
TAGS = 'tags', _('Tag collection')
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='collections')
team = models.ForeignKey(Team, on_delete=models.SET_NULL, blank=True, null=True, related_name='collections')
title = models.CharField(max_length=200)
description = models.TextField(blank=True)
visibility = models.CharField(max_length=10, choices=Item.Visibility.choices, default=Item.Visibility.PRIVATE)
tags = models.ManyToManyField(Tag, blank=True, related_name='collections')
mode = models.CharField(max_length=10, choices=Mode.choices, default=Mode.MANUAL)
filter_tags = models.ManyToManyField(Tag, blank=True, related_name='tag_collections')
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)