Browse Source

Delete unnecessary models

pull/110/head
Hironsan 5 years ago
parent
commit
141d1717d6
3 changed files with 27 additions and 109 deletions
  1. 75
      app/server/migrations/0004_auto_20190306_0626.py
  2. 33
      app/server/models.py
  3. 28
      app/server/tests/test_serializers.py

app/server/migrations/0004_created_at.py → app/server/migrations/0004_auto_20190306_0626.py

@ -1,4 +1,4 @@
# Generated by Django 2.1.5 on 2019-02-25 01:38
# Generated by Django 2.1.5 on 2019-03-06 06:26
from django.db import migrations, models
import django.db.models.deletion
@ -8,70 +8,48 @@ import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('server', '0003_shortcut'),
]
operations = [
migrations.CreateModel(
name='Seq2seqDocument',
fields=[
],
options={
'proxy': True,
'indexes': [],
},
bases=('server.document',),
),
migrations.CreateModel(
name='Seq2seqProject',
fields=[
('project_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='server.Project')),
],
options={
'proxy': True,
'indexes': [],
'abstract': False,
'base_manager_name': 'objects',
},
bases=('server.project',),
),
migrations.CreateModel(
name='SequenceLabelingDocument',
fields=[
],
options={
'proxy': True,
'indexes': [],
},
bases=('server.document',),
),
migrations.CreateModel(
name='SequenceLabelingProject',
fields=[
('project_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='server.Project')),
],
options={
'proxy': True,
'indexes': [],
'abstract': False,
'base_manager_name': 'objects',
},
bases=('server.project',),
),
migrations.CreateModel(
name='TextClassificationDocument',
fields=[
],
options={
'proxy': True,
'indexes': [],
},
bases=('server.document',),
),
migrations.CreateModel(
name='TextClassificationProject',
fields=[
('project_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='server.Project')),
],
options={
'proxy': True,
'indexes': [],
'abstract': False,
'base_manager_name': 'objects',
},
bases=('server.project',),
),
migrations.AlterModelOptions(
name='project',
options={'base_manager_name': 'objects'},
),
migrations.AddField(
model_name='document',
name='created_at',
@ -105,6 +83,11 @@ class Migration(migrations.Migration):
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='project',
name='polymorphic_ctype',
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_server.project_set+', to='contenttypes.ContentType'),
),
migrations.AddField(
model_name='seq2seqannotation',
name='created_at',
@ -127,24 +110,14 @@ class Migration(migrations.Migration):
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AlterField(
model_name='documentannotation',
name='document',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='doc_annotations', to='server.TextClassificationDocument'),
),
migrations.AlterField(
model_name='project',
name='description',
field=models.TextField(),
field=models.TextField(default=''),
),
migrations.AlterField(
model_name='seq2seqannotation',
name='document',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='seq2seq_annotations', to='server.Seq2seqDocument'),
),
migrations.AlterField(
model_name='sequenceannotation',
name='document',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='seq_annotations', to='server.SequenceLabelingDocument'),
model_name='project',
name='guideline',
field=models.TextField(default=''),
),
]

33
app/server/models.py

@ -164,33 +164,6 @@ class Document(models.Model):
return self.text[:50]
class TextClassificationDocument(Document):
class Meta:
proxy = True
def get_annotations(self):
return self.doc_annotations.all()
class SequenceLabelingDocument(Document):
class Meta:
proxy = True
def get_annotations(self):
return self.seq_annotations.all()
class Seq2seqDocument(Document):
class Meta:
proxy = True
def get_annotations(self):
return self.seq2seq_annotations.all()
class Annotation(models.Model):
prob = models.FloatField(default=0.0)
manual = models.BooleanField(default=False)
@ -203,7 +176,7 @@ class Annotation(models.Model):
class DocumentAnnotation(Annotation):
document = models.ForeignKey(TextClassificationDocument, related_name='doc_annotations', on_delete=models.CASCADE)
document = models.ForeignKey(Document, related_name='doc_annotations', on_delete=models.CASCADE)
label = models.ForeignKey(Label, on_delete=models.CASCADE)
class Meta:
@ -211,7 +184,7 @@ class DocumentAnnotation(Annotation):
class SequenceAnnotation(Annotation):
document = models.ForeignKey(SequenceLabelingDocument, related_name='seq_annotations', on_delete=models.CASCADE)
document = models.ForeignKey(Document, related_name='seq_annotations', on_delete=models.CASCADE)
label = models.ForeignKey(Label, on_delete=models.CASCADE)
start_offset = models.IntegerField()
end_offset = models.IntegerField()
@ -225,7 +198,7 @@ class SequenceAnnotation(Annotation):
class Seq2seqAnnotation(Annotation):
document = models.ForeignKey(Seq2seqDocument, related_name='seq2seq_annotations', on_delete=models.CASCADE)
document = models.ForeignKey(Document, related_name='seq2seq_annotations', on_delete=models.CASCADE)
text = models.TextField()
class Meta:

28
app/server/tests/test_serializers.py

@ -1,28 +0,0 @@
from django.test import TestCase
from mixer.backend.django import mixer
from ..serializers import LabelSerializer
from ..serializers import Seq2seqAnnotationSerializer
class TestLabelSerializer(TestCase):
def test_create(self):
label = mixer.blend('server.Label')
serializer = LabelSerializer(label)
self.assertIsInstance(serializer.data, dict)
def test_annotation(self):
from rest_framework import serializers
from ..models import Seq2seqDocument
class HogeSerializer(serializers.ModelSerializer):
seq2seq_annotations = Seq2seqAnnotationSerializer(many=True)
class Meta:
model = Seq2seqDocument
fields = ('id', 'text', 'seq2seq_annotations')
doc = mixer.blend('server.Seq2seqDocument')
ann = mixer.blend('server.Seq2seqAnnotation')
doc.seq2seq_annotations.add(ann)
serializer = HogeSerializer(doc)
print(serializer.data)
Loading…
Cancel
Save