From 7a46806643ea22c7a2779648fff8281ac18ee283 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:23:50 -0800 Subject: [PATCH] Migrate to matching model --- ..._insensitive_customfield_match_and_more.py | 55 +++++++++++++++++++ src/documents/models.py | 8 ++- src/documents/serialisers.py | 7 ++- 3 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 src/documents/migrations/1061_customfield_is_insensitive_customfield_match_and_more.py diff --git a/src/documents/migrations/1061_customfield_is_insensitive_customfield_match_and_more.py b/src/documents/migrations/1061_customfield_is_insensitive_customfield_match_and_more.py new file mode 100644 index 000000000..dea14ae4a --- /dev/null +++ b/src/documents/migrations/1061_customfield_is_insensitive_customfield_match_and_more.py @@ -0,0 +1,55 @@ +# Generated by Django 5.1.4 on 2024-12-13 21:21 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations +from django.db import models + + +class Migration(migrations.Migration): + dependencies = [ + ("documents", "1060_alter_customfieldinstance_value_select"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AddField( + model_name="customfield", + name="is_insensitive", + field=models.BooleanField(default=True, verbose_name="is insensitive"), + ), + migrations.AddField( + model_name="customfield", + name="match", + field=models.CharField(blank=True, max_length=256, verbose_name="match"), + ), + migrations.AddField( + model_name="customfield", + name="matching_algorithm", + field=models.PositiveIntegerField( + choices=[ + (0, "None"), + (1, "Any word"), + (2, "All words"), + (3, "Exact match"), + (4, "Regular expression"), + (5, "Fuzzy word"), + (6, "Automatic"), + ], + default=0, + verbose_name="matching algorithm", + ), + ), + migrations.AddField( + model_name="customfield", + name="owner", + field=models.ForeignKey( + blank=True, + default=None, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to=settings.AUTH_USER_MODEL, + verbose_name="owner", + ), + ), + ] diff --git a/src/documents/models.py b/src/documents/models.py index 4b3f97e50..2409be58a 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -719,7 +719,7 @@ class ShareLink(SoftDeleteModel): return f"Share Link for {self.document.title}" -class CustomField(models.Model): +class CustomField(MatchingModel): """ Defines the name and type of a custom field """ @@ -760,6 +760,12 @@ class CustomField(models.Model): ), ) + matching_algorithm = models.PositiveIntegerField( + _("matching algorithm"), + choices=MatchingModel.MATCHING_ALGORITHMS, + default=MatchingModel.MATCH_NONE, # override with CustomField.FieldDataType.NONE + ) + class Meta: ordering = ("created",) verbose_name = _("custom field") diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 5a87092b8..44a764a4f 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -582,7 +582,7 @@ class StoragePathField(serializers.PrimaryKeyRelatedField): return StoragePath.objects.all() -class CustomFieldSerializer(serializers.ModelSerializer): +class CustomFieldSerializer(MatchingModelSerializer, serializers.ModelSerializer): def __init__(self, *args, **kwargs): context = kwargs.get("context") self.api_version = int( @@ -597,8 +597,6 @@ class CustomFieldSerializer(serializers.ModelSerializer): read_only=False, ) - document_count = serializers.IntegerField(read_only=True) - class Meta: model = CustomField fields = [ @@ -607,6 +605,9 @@ class CustomFieldSerializer(serializers.ModelSerializer): "data_type", "extra_data", "document_count", + "match", + "matching_algorithm", + "is_insensitive", ] def validate(self, attrs):