Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

automatically update documents whenever a tag or correspondent is changed (this should make the document_retagger and document_correspondent managers somewhat obsolete (?)

Jonas Winklere143a20f5048
diff --git a/src/documents/admin.py b/src/documents/admin.py
index 6a32edc9b..ca0017f59 100755
--- a/src/documents/admin.py
+++ b/src/documents/admin.py
@@ -110,6 +110,13 @@ class CorrespondentAdmin(CommonAdmin):
list_filter = ("matching_algorithm",)
list_editable = ("match", "matching_algorithm")
+ def save_model(self, request, obj, form, change):
+ super().save_model(request, obj, form, change)
+
+ for document in Document.objects.filter(correspondent__isnull=True).exclude(tags__is_archived_tag=True):
+ if obj.matches(document.content):
+ document.correspondent = obj
+ document.save(update_fields=("correspondent",))
class TagAdmin(CommonAdmin):
@@ -117,6 +124,13 @@ class TagAdmin(CommonAdmin):
list_filter = ("colour", "matching_algorithm")
list_editable = ("colour", "match", "matching_algorithm")
+ def save_model(self, request, obj, form, change):
+ super().save_model(request, obj, form, change)
+
+ for document in Document.objects.all().exclude(tags__is_archived_tag=True):
+ if obj.matches(document.content):
+ document.tags.add(obj)
+
class DocumentAdmin(CommonAdmin):