Browse Source

Add uuid field to label models

pull/1823/head
Hironsan 2 years ago
parent
commit
9132d8745d
5 changed files with 163 additions and 0 deletions
  1. 66
      backend/data_export/migrations/0001_initial.py
  2. 34
      backend/labels/migrations/0012_add_uuid_field.py
  3. 27
      backend/labels/migrations/0013_populate_uuid_values.py
  4. 33
      backend/labels/migrations/0014_remove_uuid_null.py
  5. 3
      backend/labels/models.py

66
backend/data_export/migrations/0001_initial.py

@ -0,0 +1,66 @@
# Generated by Django 4.0.2 on 2022-05-12 02:27
from django.db import migrations
class Migration(migrations.Migration):
initial = True
dependencies = [
("examples", "0006_alter_example_upload_name"),
("labels", "0012_add_uuid_field"),
]
operations = [
migrations.CreateModel(
name="ExportedCategory",
fields=[],
options={
"proxy": True,
"indexes": [],
"constraints": [],
},
bases=("labels.category",),
),
migrations.CreateModel(
name="ExportedExample",
fields=[],
options={
"proxy": True,
"indexes": [],
"constraints": [],
},
bases=("examples.example",),
),
migrations.CreateModel(
name="ExportedRelation",
fields=[],
options={
"proxy": True,
"indexes": [],
"constraints": [],
},
bases=("labels.relation",),
),
migrations.CreateModel(
name="ExportedSpan",
fields=[],
options={
"proxy": True,
"indexes": [],
"constraints": [],
},
bases=("labels.span",),
),
migrations.CreateModel(
name="ExportedText",
fields=[],
options={
"proxy": True,
"indexes": [],
"constraints": [],
},
bases=("labels.textlabel",),
),
]

34
backend/labels/migrations/0012_add_uuid_field.py

@ -0,0 +1,34 @@
# Generated by Django 4.0.2 on 2022-05-12 02:27
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
("labels", "0011_remove_relation_direction"),
]
operations = [
migrations.AddField(
model_name="category",
name="uuid",
field=models.UUIDField(default=uuid.uuid4, null=True),
),
migrations.AddField(
model_name="relation",
name="uuid",
field=models.UUIDField(default=uuid.uuid4, null=True),
),
migrations.AddField(
model_name="span",
name="uuid",
field=models.UUIDField(default=uuid.uuid4, null=True),
),
migrations.AddField(
model_name="textlabel",
name="uuid",
field=models.UUIDField(default=uuid.uuid4, null=True),
),
]

27
backend/labels/migrations/0013_populate_uuid_values.py

@ -0,0 +1,27 @@
# Generated by Django 4.0.2 on 2022-05-12 02:28
from django.db import migrations
import uuid
def gen_uuid(apps, schema_editor):
Category = apps.get_model("labels", "Category")
Span = apps.get_model("labels", "Span")
Relation = apps.get_model("labels", "Relation")
TextLabel = apps.get_model("labels", "TextLabel")
for label in [Category, Span, Relation, TextLabel]:
for row in label.objects.all():
row.uuid = uuid.uuid4()
row.save(update_fields=["uuid"])
class Migration(migrations.Migration):
dependencies = [
("labels", "0012_add_uuid_field"),
]
operations = [
migrations.RunPython(gen_uuid, reverse_code=migrations.RunPython.noop),
]

33
backend/labels/migrations/0014_remove_uuid_null.py

@ -0,0 +1,33 @@
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("labels", "0013_populate_uuid_values"),
]
operations = [
migrations.AlterField(
model_name="category",
name="uuid",
field=models.UUIDField(default=uuid.uuid4, unique=True),
),
migrations.AlterField(
model_name="relation",
name="uuid",
field=models.UUIDField(default=uuid.uuid4, unique=True),
),
migrations.AlterField(
model_name="span",
name="uuid",
field=models.UUIDField(default=uuid.uuid4, unique=True),
),
migrations.AlterField(
model_name="textlabel",
name="uuid",
field=models.UUIDField(default=uuid.uuid4, unique=True),
),
]

3
backend/labels/models.py

@ -1,3 +1,5 @@
import uuid
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.db import models
@ -16,6 +18,7 @@ from label_types.models import CategoryType, RelationType, SpanType
class Label(models.Model):
objects = LabelManager()
uuid = models.UUIDField(default=uuid.uuid4, unique=True)
prob = models.FloatField(default=0.0)
manual = models.BooleanField(default=False)
user = models.ForeignKey(User, on_delete=models.CASCADE)

Loading…
Cancel
Save