mirror of https://github.com/doccano/doccano.git
7 changed files with 102 additions and 33 deletions
Split View
Diff Options
-
26backend/api/migrations/0030_delete_autolabelingconfig.py
-
30backend/api/models.py
-
2backend/auto_labeling/admin.py
-
37backend/auto_labeling/migrations/0001_initial.py
-
34backend/auto_labeling/models.py
-
3backend/auto_labeling/serializers.py
-
3backend/auto_labeling/views.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' |
|||
) |
|||
] |
|||
) |
|||
] |
@ -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=[] |
|||
) |
|||
] |
@ -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) |
Write
Preview
Loading…
Cancel
Save