mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Fix: Make customfieldinstance soft delete, fix filepath when deleted (#8067)
This commit is contained in:
		| @@ -0,0 +1,58 @@ | ||||
| # Generated by Django 5.1.2 on 2024-10-28 01:55 | ||||
|  | ||||
| from django.db import migrations | ||||
| from django.db import models | ||||
|  | ||||
|  | ||||
| class Migration(migrations.Migration): | ||||
|     dependencies = [ | ||||
|         ("documents", "1055_alter_storagepath_path"), | ||||
|     ] | ||||
|  | ||||
|     operations = [ | ||||
|         migrations.AddField( | ||||
|             model_name="customfieldinstance", | ||||
|             name="deleted_at", | ||||
|             field=models.DateTimeField(blank=True, null=True), | ||||
|         ), | ||||
|         migrations.AddField( | ||||
|             model_name="customfieldinstance", | ||||
|             name="restored_at", | ||||
|             field=models.DateTimeField(blank=True, null=True), | ||||
|         ), | ||||
|         migrations.AddField( | ||||
|             model_name="customfieldinstance", | ||||
|             name="transaction_id", | ||||
|             field=models.UUIDField(blank=True, null=True), | ||||
|         ), | ||||
|         migrations.AddField( | ||||
|             model_name="note", | ||||
|             name="deleted_at", | ||||
|             field=models.DateTimeField(blank=True, null=True), | ||||
|         ), | ||||
|         migrations.AddField( | ||||
|             model_name="note", | ||||
|             name="restored_at", | ||||
|             field=models.DateTimeField(blank=True, null=True), | ||||
|         ), | ||||
|         migrations.AddField( | ||||
|             model_name="note", | ||||
|             name="transaction_id", | ||||
|             field=models.UUIDField(blank=True, null=True), | ||||
|         ), | ||||
|         migrations.AddField( | ||||
|             model_name="sharelink", | ||||
|             name="deleted_at", | ||||
|             field=models.DateTimeField(blank=True, null=True), | ||||
|         ), | ||||
|         migrations.AddField( | ||||
|             model_name="sharelink", | ||||
|             name="restored_at", | ||||
|             field=models.DateTimeField(blank=True, null=True), | ||||
|         ), | ||||
|         migrations.AddField( | ||||
|             model_name="sharelink", | ||||
|             name="transaction_id", | ||||
|             field=models.UUIDField(blank=True, null=True), | ||||
|         ), | ||||
|     ] | ||||
| @@ -710,7 +710,7 @@ class PaperlessTask(models.Model): | ||||
|         return f"Task {self.task_id}" | ||||
|  | ||||
|  | ||||
| class Note(models.Model): | ||||
| class Note(SoftDeleteModel): | ||||
|     note = models.TextField( | ||||
|         _("content"), | ||||
|         blank=True, | ||||
| @@ -750,7 +750,7 @@ class Note(models.Model): | ||||
|         return self.note | ||||
|  | ||||
|  | ||||
| class ShareLink(models.Model): | ||||
| class ShareLink(SoftDeleteModel): | ||||
|     class FileVersion(models.TextChoices): | ||||
|         ARCHIVE = ("archive", _("Archive")) | ||||
|         ORIGINAL = ("original", _("Original")) | ||||
| @@ -866,7 +866,7 @@ class CustomField(models.Model): | ||||
|         return f"{self.name} : {self.data_type}" | ||||
|  | ||||
|  | ||||
| class CustomFieldInstance(models.Model): | ||||
| class CustomFieldInstance(SoftDeleteModel): | ||||
|     """ | ||||
|     A single instance of a field, attached to a CustomField for the name and type | ||||
|     and attached to a single Document to be metadata for it | ||||
|   | ||||
| @@ -855,6 +855,8 @@ class DocumentSerializer( | ||||
|                 super().update(instance, validated_data) | ||||
|         else: | ||||
|             super().update(instance, validated_data) | ||||
|         # hard delete custom field instances that were soft deleted | ||||
|         CustomFieldInstance.deleted_objects.filter(document=instance).delete() | ||||
|         return instance | ||||
|  | ||||
|     def __init__(self, *args, **kwargs): | ||||
|   | ||||
| @@ -296,7 +296,7 @@ def validate_filepath_template_and_render( | ||||
|     else: | ||||
|         # or use the real document information | ||||
|         tags_list = document.tags.order_by("name").all() | ||||
|         custom_fields = document.custom_fields.all() | ||||
|         custom_fields = CustomFieldInstance.global_objects.filter(document=document) | ||||
|  | ||||
|     # Build the context dictionary | ||||
|     context = ( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 shamoon
					shamoon