mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-13 01:57:08 +01:00
Enhancement: auto-update document filenames with CF select fields (#8045)
This commit is contained in:
parent
b2e9f3195a
commit
149d770ad1
2 changed files with 57 additions and 0 deletions
|
|
@ -29,6 +29,7 @@ from documents.data_models import DocumentMetadataOverrides
|
|||
from documents.file_handling import create_source_path_directory
|
||||
from documents.file_handling import delete_empty_directories
|
||||
from documents.file_handling import generate_unique_filename
|
||||
from documents.models import CustomField
|
||||
from documents.models import CustomFieldInstance
|
||||
from documents.models import Document
|
||||
from documents.models import MatchingModel
|
||||
|
|
@ -364,6 +365,20 @@ class CannotMoveFilesException(Exception):
|
|||
pass
|
||||
|
||||
|
||||
@receiver(models.signals.post_save, sender=CustomField)
|
||||
def update_cf_instance_documents(sender, instance: CustomField, **kwargs):
|
||||
"""
|
||||
'Select' custom field instances get their end-user value (e.g. in file names) from the select_options in extra_data,
|
||||
which is contained in the custom field itself. So when the field is changed, we (may) need to update the file names
|
||||
of all documents that have this custom field.
|
||||
"""
|
||||
if (
|
||||
instance.data_type == CustomField.FieldDataType.SELECT
|
||||
): # Only select fields, for now
|
||||
for cf_instance in instance.fields.all():
|
||||
update_filename_and_move_files(sender, cf_instance)
|
||||
|
||||
|
||||
@receiver(models.signals.post_save, sender=CustomFieldInstance)
|
||||
@receiver(models.signals.m2m_changed, sender=Document.tags.through)
|
||||
@receiver(models.signals.post_save, sender=Document)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue