Skip to content

Commit

Permalink
CU-8697qrm0k: unique constraint on models and model pack viewset
Browse files Browse the repository at this point in the history
  • Loading branch information
tomolopolis committed Jan 30, 2025
1 parent 04cd016 commit 47837d0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ tmp.py

# docs outputs
docs/_build

# macOS system files
.DS_Store
*/.DS_Store

# Jupyter Notebook checkpoints
*/.ipynb_checkpoints/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated by Django 5.1.4 on 2025-01-29 23:30

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0084_conceptdb_create_time_conceptdb_last_modified_and_more'),
]

operations = [
migrations.AlterField(
model_name='conceptdb',
name='name',
field=models.CharField(blank=True, default='', max_length=100, unique=True, validators=[django.core.validators.RegexValidator('^[0-9a-zA-Z_-]*$', 'Only alpahanumeric characters, -, _ are allowed for CDB names')]),
),
migrations.AlterField(
model_name='dataset',
name='name',
field=models.CharField(max_length=150, unique=True),
),
migrations.AlterField(
model_name='metacatmodel',
name='name',
field=models.CharField(help_text='The task name followed by the underlying model impl', max_length=100, unique=True),
),
migrations.AlterField(
model_name='metataskvalue',
name='name',
field=models.CharField(max_length=150, unique=True),
),
migrations.AlterField(
model_name='modelpack',
name='name',
field=models.TextField(unique=True),
),
migrations.AlterField(
model_name='project',
name='name',
field=models.CharField(help_text='A name of the annotation project', max_length=150, unique=True),
),
migrations.AlterField(
model_name='projectgroup',
name='name',
field=models.CharField(help_text='A name of the annotation project', max_length=150, unique=True),
),
]
12 changes: 6 additions & 6 deletions webapp/api/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


class ModelPack(models.Model):
name = models.TextField(help_text='')
name = models.TextField(help_text='', unique=True)
model_pack = models.FileField(help_text='Model pack zip')
concept_db = models.ForeignKey('ConceptDB', on_delete=models.CASCADE, blank=True, null=True)
vocab = models.ForeignKey('Vocabulary', on_delete=models.CASCADE, blank=True, null=True)
Expand Down Expand Up @@ -96,7 +96,7 @@ def __str__(self):


class ConceptDB(models.Model):
name = models.CharField(max_length=100, default='', blank=True, validators=[cdb_name_validator])
name = models.CharField(max_length=100, default='', blank=True, validators=[cdb_name_validator], unique=True)
cdb_file = models.FileField()
use_for_training = models.BooleanField(default=True)
create_time = models.DateTimeField(auto_now_add=True)
Expand Down Expand Up @@ -150,7 +150,7 @@ def __str__(self):


class MetaCATModel(models.Model):
name = models.CharField(max_length=100, help_text="The task name followed by the underlying model impl")
name = models.CharField(max_length=100, help_text="The task name followed by the underlying model impl", unique=True)
meta_cat_dir = models.FilePathField(help_text='The zip or dir for a MetaCAT model, not editable, '
'is set via a model pack .zip upload',
allow_folders=True, editable=False)
Expand Down Expand Up @@ -195,7 +195,7 @@ def __str__(self):


class Dataset(models.Model):
name = models.CharField(max_length=150)
name = models.CharField(max_length=150, unique=True)
original_file = models.FileField()
create_time = models.DateTimeField(auto_now_add=True)
description = models.TextField(default="", blank=True)
Expand Down Expand Up @@ -241,7 +241,7 @@ class Meta:
("C", "Complete"),
]

name = models.CharField(max_length=150, help_text='A name of the annotation project')
name = models.CharField(max_length=150, help_text='A name of the annotation project', unique=True)
description = models.TextField(default="", blank=True, help_text='A short description of the annotations to be '
'collected and why')
dataset = models.ForeignKey('Dataset', on_delete=models.CASCADE, help_text='The dataset to be annotated.')
Expand Down Expand Up @@ -356,7 +356,7 @@ def __str__(self):


class MetaTaskValue(models.Model):
name = models.CharField(max_length=150)
name = models.CharField(max_length=150, unique=True)
ordering = models.PositiveSmallIntegerField(help_text="the order in which the meta task value will appear in "
"the Trainer Annotation project screen", default=0)

Expand Down
9 changes: 8 additions & 1 deletion webapp/api/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,16 @@ class VocabularyViewSet(viewsets.ModelViewSet):
serializer_class = VocabularySerializer


class ModelPackViewSet(viewsets.ModelViewSet):
permission_classes = [permissions.IsAuthenticated]
http_method_names = ['get', 'post', 'head', 'delete']
queryset = ModelPack.objects.all()
serializer_class = ModelPackSerializer


class DatasetViewSet(viewsets.ModelViewSet):
permission_classes = [permissions.IsAuthenticated]
http_method_names = ['get']
http_method_names = ['get', 'post']
queryset = Dataset.objects.all()
serializer_class = DatasetSerializer

Expand Down
1 change: 1 addition & 0 deletions webapp/api/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
router.register(r'entity-relations', api.views.EntityRelationViewSet)
router.register(r'concept-dbs', api.views.ConceptDBViewSet)
router.register(r'vocabs', api.views.VocabularyViewSet)
router.register(r'modelpacks', api.views.ModelPackViewSet)
router.register(r'datasets', api.views.DatasetViewSet)


Expand Down

0 comments on commit 47837d0

Please sign in to comment.