Browse Source

Rename model method

pull/10/head
Hironsan 6 years ago
parent
commit
5c08f73398
3 changed files with 7 additions and 9 deletions
  1. BIN
      app/db.sqlite3
  2. 12
      app/server/models.py
  3. 4
      app/server/views.py

BIN
app/db.sqlite3

12
app/server/models.py

@ -5,8 +5,6 @@ from django.contrib.auth.models import User
from django.contrib.staticfiles.storage import staticfiles_storage
class Project(models.Model):
DOCUMENT_CLASSIFICATION = 'DocumentClassification'
SEQUENCE_LABELING = 'SequenceLabeling'
@ -89,7 +87,7 @@ class Project(models.Model):
elif self.is_type_of(Project.Seq2seq):
return Seq2seqAnnotationSerializer
def get_annotation_class(self, project):
def get_annotation_class(self):
if self.is_type_of(Project.DOCUMENT_CLASSIFICATION):
return DocumentAnnotation
elif self.is_type_of(Project.SEQUENCE_LABELING):
@ -125,13 +123,13 @@ class Document(models.Model):
text = models.TextField()
project = models.ForeignKey(Project, related_name='documents', on_delete=models.CASCADE)
def get_annotations(self, document):
def get_annotations(self):
if self.project.is_type_of(Project.DOCUMENT_CLASSIFICATION):
return document.doc_annotations.all()
return self.doc_annotations.all()
elif self.project.is_type_of(Project.SEQUENCE_LABELING):
return document.seq_annotations.all()
return self.seq_annotations.all()
elif self.project.is_type_of(Project.Seq2seq):
return document.seq2seq_annotations.all()
return self.seq2seq_annotations.all()
def __str__(self):
return self.text[:50]

4
app/server/views.py

@ -203,7 +203,7 @@ class AnnotationsAPI(generics.ListCreateAPIView):
project = get_object_or_404(Project, pk=project_id)
doc_id = self.kwargs['doc_id']
document = get_object_or_404(Document, pk=doc_id, project=project)
self.queryset = document.get_annotations_by_doc()
self.queryset = document.get_annotations()
return self.queryset
@ -239,7 +239,7 @@ class AnnotationAPI(generics.RetrieveUpdateDestroyAPIView):
def get_queryset(self):
doc_id = self.kwargs['doc_id']
document = get_object_or_404(Document, pk=doc_id)
self.queryset = document.get_annotations_by_doc()
self.queryset = document.get_annotations()
return self.queryset

Loading…
Cancel
Save