Skip to content

Commit

Permalink
Slightly improve serializers.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmanovic committed Jan 24, 2019
1 parent 056e4c4 commit b1d0867
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
12 changes: 6 additions & 6 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from cvat.apps.engine.models import Task, Job, Label, AttributeSpec
from django.contrib.auth.models import User, Group

class AttributeSerializer(serializers.PrimaryKeyRelatedField, serializers.ModelSerializer):
class AttributeSerializer(serializers.ModelSerializer):
class Meta:
model = AttributeSpec
fields = ('id', 'text')

class LabelSerializer(serializers.PrimaryKeyRelatedField, serializers.ModelSerializer):
class LabelSerializer(serializers.ModelSerializer):
attributes = AttributeSerializer(many=True, source='attributespec_set')
class Meta:
model = Label
Expand All @@ -21,12 +21,12 @@ def create(self, validated_data):

return label


class TaskSerializer(serializers.ModelSerializer):
labels = LabelSerializer(many=True, source='label_set')

class Meta:
model = Task
fields = ('id', 'name', 'size', 'mode', 'owner', 'assignee',
fields = ('url', 'id', 'name', 'size', 'mode', 'owner', 'assignee',
'bug_tracker', 'created_date', 'updated_date', 'overlap',
'z_order', 'flipped', 'status', 'labels')
read_only_fields = ('size', 'mode', 'created_date', 'updated_date',
Expand All @@ -41,7 +41,7 @@ def create(self, validated_data):
return task


class JobSerializer(serializers.HyperlinkedModelSerializer):
class JobSerializer(serializers.ModelSerializer):
task_id = serializers.ReadOnlyField(source="segment.task.id")
start_frame = serializers.ReadOnlyField(source="segment.start_frame")
stop_frame = serializers.ReadOnlyField(source="segment.stop_frame")
Expand All @@ -52,7 +52,7 @@ class Meta:
'stop_frame', 'max_shape_id', 'task_id')
read_only_fields = ('max_shape_id',)

class UserSerializer(serializers.HyperlinkedModelSerializer):
class UserSerializer(serializers.ModelSerializer):
groups = serializers.SlugRelatedField(many=True,
slug_field='name', queryset=Group.objects.all())

Expand Down
10 changes: 3 additions & 7 deletions cvat/apps/engine/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@
# GET and PATCH the specific job
path(REST_API_PREFIX + 'jobs/<int:pk>', views.JobDetail.as_view(),
name='job-detail'),





# GET a list of annotation tasks, POST an annotation task
path(REST_API_PREFIX + 'tasks/', views.TaskList.as_view(),
name='task-list'),
path( # GET, DELETE, PATCH
REST_API_PREFIX + 'tasks/<int:pk>',
views.TaskDetail.as_view(),
REST_API_PREFIX + 'tasks/<int:pk>', views.TaskDetail.as_view(),
name='task-detail'),


path( # GET, DELETE, PATCH, PUT
REST_API_PREFIX + 'tasks/<int:pk>/annotations/',
views.dummy_view,
Expand Down

0 comments on commit b1d0867

Please sign in to comment.