From e143a20f5048ce2f170cdbf7b2485c701f70badb Mon Sep 17 00:00:00 2001 From: Jonas Winkler Date: Fri, 6 Jul 2018 13:51:50 +0200 Subject: [PATCH] automatically update documents whenever a tag or correspondent is changed (this should make the document_retagger and document_correspondent managers somewhat obsolete (?) --- src/documents/admin.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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):