mirror of https://github.com/doccano/doccano.git
Chris
3 years ago
7 changed files with 82 additions and 6 deletions
Split View
Diff Options
-
10app/api/admin.py
-
22app/api/migrations/0009_tag.py
-
8app/api/models.py
-
15app/api/serializers.py
-
6app/api/urls.py
-
3app/api/views/__init__.py
-
24app/api/views/tag.py
@ -0,0 +1,22 @@ |
|||
# Generated by Django 3.2 on 2021-04-13 16:50 |
|||
|
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('api', '0008_auto_20210302_1013'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.CreateModel( |
|||
name='Tag', |
|||
fields=[ |
|||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
|||
('text', models.TextField()), |
|||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tags', to='api.project')), |
|||
], |
|||
), |
|||
] |
@ -0,0 +1,24 @@ |
|||
from django.shortcuts import get_object_or_404 |
|||
from rest_framework import generics, status |
|||
from rest_framework.response import Response |
|||
|
|||
from ..models import Project, Tag |
|||
from ..serializers import TagSerializer |
|||
|
|||
|
|||
class TagList(generics.ListCreateAPIView): |
|||
serializer_class = TagSerializer |
|||
pagination_class = None |
|||
|
|||
def get_queryset(self): |
|||
project = get_object_or_404(Project, pk=self.kwargs['project_id']) |
|||
return project.tags |
|||
|
|||
def perform_create(self, serializer): |
|||
project = get_object_or_404(Project, pk=self.kwargs['project_id']) |
|||
serializer.save(project=project) |
|||
|
|||
def delete(self, request, *args, **kwargs): |
|||
delete_id = request.data['id'] |
|||
Tag.objects.get(id=delete_id).delete() |
|||
return Response(status=status.HTTP_204_NO_CONTENT) |
Write
Preview
Loading…
Cancel
Save