Migrate to matching model
This commit is contained in:
		
							parent
							
								
									5d6cfa7349
								
							
						
					
					
						commit
						7a46806643
					
				| @ -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", | ||||
|             ), | ||||
|         ), | ||||
|     ] | ||||
| @ -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") | ||||
|  | ||||
| @ -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): | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user