diff --git a/backend/api/migrations/0030_delete_autolabelingconfig.py b/backend/api/migrations/0030_delete_autolabelingconfig.py new file mode 100644 index 00000000..462d5a27 --- /dev/null +++ b/backend/api/migrations/0030_delete_autolabelingconfig.py @@ -0,0 +1,26 @@ +# Generated by Django 3.2.11 on 2022-01-20 04:17 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0029_auto_20220119_2333'), + ] + + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.DeleteModel( + name='AutoLabelingConfig', + ), + ], + database_operations=[ + migrations.AlterModelTable( + name='AutoLabelingConfig', + table='auto_labeling_autolabelingconfig' + ) + ] + ) + ] diff --git a/backend/api/models.py b/backend/api/models.py index 28e12a18..8ecae2b0 100644 --- a/backend/api/models.py +++ b/backend/api/models.py @@ -3,7 +3,6 @@ import random import string import uuid -from auto_labeling_pipeline.models import RequestModelFactory from django.contrib.auth.models import User from django.core.exceptions import ValidationError from django.db import models @@ -412,35 +411,6 @@ class TextLabel(Annotation): ) -class AutoLabelingConfig(models.Model): - model_name = models.CharField(max_length=100) - model_attrs = models.JSONField(default=dict) - template = models.TextField(default='') - label_mapping = models.JSONField(default=dict, blank=True) - project = models.ForeignKey( - to=Project, - on_delete=models.CASCADE, - related_name='auto_labeling_config' - ) - default = models.BooleanField(default=False) - created_at = models.DateTimeField(auto_now_add=True) - updated_at = models.DateTimeField(auto_now=True) - - def __str__(self): - return self.model_name - - def clean_fields(self, exclude=None): - super().clean_fields(exclude=exclude) - try: - RequestModelFactory.find(self.model_name) - except NameError: - message = f'The specified model name {self.model_name} does not exist.' - raise ValidationError(message) - except Exception: - message = 'The attributes does not match the model.' - raise ValidationError(message) - - class RelationTypes(models.Model): color = models.TextField() name = models.TextField() diff --git a/backend/auto_labeling/admin.py b/backend/auto_labeling/admin.py index 411e850f..7495bcf8 100644 --- a/backend/auto_labeling/admin.py +++ b/backend/auto_labeling/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from api.models import AutoLabelingConfig +from .models import AutoLabelingConfig class AutoLabelingConfigAdmin(admin.ModelAdmin): diff --git a/backend/auto_labeling/migrations/0001_initial.py b/backend/auto_labeling/migrations/0001_initial.py new file mode 100644 index 00000000..8cfbbf27 --- /dev/null +++ b/backend/auto_labeling/migrations/0001_initial.py @@ -0,0 +1,37 @@ +# Generated by Django 3.2.11 on 2022-01-20 04:17 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('api', '0030_delete_autolabelingconfig'), + ] + + operations = [ + migrations.SeparateDatabaseAndState( + state_operations=[ + migrations.CreateModel( + name='AutoLabelingConfig', + fields=[ + ('id', + models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('model_name', models.CharField(max_length=100)), + ('model_attrs', models.JSONField(default=dict)), + ('template', models.TextField(default='')), + ('label_mapping', models.JSONField(blank=True, default=dict)), + ('default', models.BooleanField(default=False)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, + related_name='auto_labeling_config', to='api.project')), + ], + ), + ], + database_operations=[] + ) + ] diff --git a/backend/auto_labeling/models.py b/backend/auto_labeling/models.py index e69de29b..502e6c7f 100644 --- a/backend/auto_labeling/models.py +++ b/backend/auto_labeling/models.py @@ -0,0 +1,34 @@ +from auto_labeling_pipeline.models import RequestModelFactory +from django.core.exceptions import ValidationError +from django.db import models + +from api.models import Project + + +class AutoLabelingConfig(models.Model): + model_name = models.CharField(max_length=100) + model_attrs = models.JSONField(default=dict) + template = models.TextField(default='') + label_mapping = models.JSONField(default=dict, blank=True) + project = models.ForeignKey( + to=Project, + on_delete=models.CASCADE, + related_name='auto_labeling_config' + ) + default = models.BooleanField(default=False) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + def __str__(self): + return self.model_name + + def clean_fields(self, exclude=None): + super().clean_fields(exclude=exclude) + try: + RequestModelFactory.find(self.model_name) + except NameError: + message = f'The specified model name {self.model_name} does not exist.' + raise ValidationError(message) + except Exception: + message = 'The attributes does not match the model.' + raise ValidationError(message) diff --git a/backend/auto_labeling/serializers.py b/backend/auto_labeling/serializers.py index 857d7d10..4bf52d2b 100644 --- a/backend/auto_labeling/serializers.py +++ b/backend/auto_labeling/serializers.py @@ -1,9 +1,10 @@ from auto_labeling_pipeline.models import RequestModelFactory from rest_framework import serializers -from api.models import AutoLabelingConfig, DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ, SPEECH2TEXT, \ +from api.models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, SEQ2SEQ, SPEECH2TEXT, \ IMAGE_CLASSIFICATION from api.serializers import CategorySerializer, SpanSerializer, TextLabelSerializer +from .models import AutoLabelingConfig class AutoLabelingConfigSerializer(serializers.ModelSerializer): diff --git a/backend/auto_labeling/views.py b/backend/auto_labeling/views.py index 41c44c98..345d2724 100644 --- a/backend/auto_labeling/views.py +++ b/backend/auto_labeling/views.py @@ -16,11 +16,12 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from api.models import AutoLabelingConfig, Example, Project +from api.models import Example, Project from members.permissions import IsInProjectOrAdmin, IsProjectAdmin from .exceptions import (AutoLabelingException, AutoLabelingPermissionDenied, AWSTokenError, SampleDataException, TemplateMappingError, URLConnectionError) +from .models import AutoLabelingConfig from .serializers import (AutoLabelingConfigSerializer, get_annotation_serializer)