Compare commits

...
Author SHA1 Message Date
jonaswinkler e283e55116 initial implementation of nested tags on the server 2021-03-07 21:33:49 +01:00
5 changed files with 61 additions and 5 deletions

No files matched your search

+7 -2
View File
@@ -1,4 +1,6 @@
from django.contrib import admin
from treebeard.admin import TreeAdmin
from treebeard.forms import movenodeform_factory
from .models import Correspondent, Document, DocumentType, Tag, \
SavedView, SavedViewFilterRule
@@ -15,13 +17,16 @@ class CorrespondentAdmin(admin.ModelAdmin):
list_editable = ("match", "matching_algorithm")
class TagAdmin(admin.ModelAdmin):
class TagAdmin(TreeAdmin):
form = movenodeform_factory(Tag)
list_display = (
"name",
"color",
"match",
"matching_algorithm"
"matching_algorithm",
"path"
)
list_filter = ("color", "matching_algorithm")
list_editable = ("color", "match", "matching_algorithm")
+3 -2
View File
@@ -52,10 +52,11 @@ class TagsFilter(Filter):
return qs
for tag_id in tag_ids:
tag = Tag.objects.get(id=tag_id)
if self.exclude:
qs = qs.exclude(tags__id=tag_id)
qs = qs.exclude(tags__path__startswith=tag.path)
else:
qs = qs.filter(tags__id=tag_id)
qs = qs.filter(tags__path__startswith=tag.path)
return qs
@@ -0,0 +1,47 @@
# Generated by Django 3.1.7 on 2021-03-07 19:55
from django.db import migrations, models
def set_path(apps, schema_editor):
Tag = apps.get_model('documents', 'Tag')
i = 1
for t in Tag.objects.order_by('name'):
t.path = f"{i:04}"
t.save()
i += 1
class Migration(migrations.Migration):
dependencies = [
('documents', '1014_auto_20210228_1614'),
]
operations = [
migrations.AddField(
model_name='tag',
name='depth',
field=models.PositiveIntegerField(default=1),
preserve_default=False,
),
migrations.AddField(
model_name='tag',
name='numchild',
field=models.PositiveIntegerField(default=0),
),
migrations.AddField(
model_name='tag',
name='path',
field=models.CharField(max_length=255, null=True, blank=True)
),
migrations.RunPython(
set_path,
migrations.RunPython.noop
),
migrations.AlterField(
model_name='tag',
name='path',
field=models.CharField(max_length=255, unique=True)
),
]
+2 -1
View File
@@ -15,6 +15,7 @@ from django.utils import timezone
from django.utils.timezone import is_aware
from django.utils.translation import gettext_lazy as _
from treebeard.mp_tree import MP_Node
from documents.parsers import get_default_file_extension
@@ -75,7 +76,7 @@ class Correspondent(MatchingModel):
verbose_name_plural = _("correspondents")
class Tag(MatchingModel):
class Tag(MatchingModel, MP_Node):
color = models.CharField(
_("color"),
+2
View File
@@ -102,6 +102,8 @@ INSTALLED_APPS = [
"django_q",
"treebeard",
] + env_apps
if DEBUG: