diff --git a/testproj/todo/models.py b/testproj/todo/models.py index 46e6300..cf7c9d7 100644 --- a/testproj/todo/models.py +++ b/testproj/todo/models.py @@ -1,3 +1,5 @@ +from decimal import Decimal + from django.db import models @@ -18,3 +20,19 @@ class TodoYetAnother(models.Model): class TodoTree(models.Model): parent = models.ForeignKey('self', on_delete=models.CASCADE, related_name='children', null=True) title = models.CharField(max_length=50) + + +class Pack(models.Model): + SIZE_10x20 = Decimal(200.000) + SIZE_10x10 = Decimal(100.000) + SIZE_5x10 = Decimal(50.000) + + size_code_choices = ( + (SIZE_5x10, '5x10'), + (SIZE_10x10, '10x10'), + (SIZE_10x20, '10x20'), + ) + size_code = models.DecimalField(max_digits=7, + decimal_places=3, + choices=size_code_choices, + default=SIZE_10x20) diff --git a/testproj/todo/serializer.py b/testproj/todo/serializer.py index 309e582..aea435c 100644 --- a/testproj/todo/serializer.py +++ b/testproj/todo/serializer.py @@ -4,7 +4,7 @@ from django.utils import timezone from rest_framework import serializers from rest_framework_recursive.fields import RecursiveField -from .models import Todo, TodoAnother, TodoTree, TodoYetAnother +from .models import Pack, Todo, TodoAnother, TodoTree, TodoYetAnother class TodoSerializer(serializers.ModelSerializer): @@ -57,3 +57,14 @@ class TodoRecursiveSerializer(serializers.ModelSerializer): class Meta: model = TodoTree fields = ('id', 'title', 'parent', 'parent_id') + + +class HarvestSerializer(serializers.ModelSerializer): + class Meta: + model = Pack + fields = ( + 'size_code', + ) + read_only_fields = ( + 'size_code', + ) diff --git a/testproj/todo/urls.py b/testproj/todo/urls.py index 1add254..8f4ca25 100644 --- a/testproj/todo/urls.py +++ b/testproj/todo/urls.py @@ -9,6 +9,7 @@ router.register(r'another', views.TodoAnotherViewSet) router.register(r'yetanother', views.TodoYetAnotherViewSet) router.register(r'tree', views.TodoTreeView) router.register(r'recursive', views.TodoRecursiveView) +router.register(r'harvest', views.HarvestViewSet) urlpatterns = router.urls diff --git a/testproj/todo/views.py b/testproj/todo/views.py index 621b9a1..17881b9 100644 --- a/testproj/todo/views.py +++ b/testproj/todo/views.py @@ -1,11 +1,13 @@ -from rest_framework import viewsets +from rest_framework import mixins, permissions, viewsets +from rest_framework.authentication import TokenAuthentication from rest_framework.generics import RetrieveAPIView from drf_yasg.utils import swagger_auto_schema -from .models import Todo, TodoAnother, TodoTree, TodoYetAnother +from .models import Pack, Todo, TodoAnother, TodoTree, TodoYetAnother from .serializer import ( - TodoAnotherSerializer, TodoRecursiveSerializer, TodoSerializer, TodoTreeSerializer, TodoYetAnotherSerializer + HarvestSerializer, TodoAnotherSerializer, TodoRecursiveSerializer, TodoSerializer, TodoTreeSerializer, + TodoYetAnotherSerializer ) @@ -75,3 +77,16 @@ class TodoRecursiveView(viewsets.ModelViewSet): @swagger_auto_schema(responses={200: TodoRecursiveSerializer(many=True)}) def list(self, request, *args, **kwargs): return super(TodoRecursiveView, self).list(request, *args, **kwargs) + + +class HarvestViewSet(mixins.ListModelMixin, + mixins.UpdateModelMixin, + viewsets.GenericViewSet): + + queryset = Pack.objects.all() + serializer_class = HarvestSerializer + permission_classes = [permissions.IsAuthenticated] + authentication_classes = [TokenAuthentication] + + def perform_update(self, serializer): + pass diff --git a/tests/reference.yaml b/tests/reference.yaml index 00d8919..94c5749 100644 --- a/tests/reference.yaml +++ b/tests/reference.yaml @@ -592,6 +592,60 @@ paths: description: A unique integer value identifying this todo another. required: true type: integer + /todo/harvest/: + get: + operationId: todo_harvest_list + description: '' + parameters: [] + responses: + '200': + description: '' + schema: + type: array + items: + $ref: '#/definitions/Harvest' + tags: + - todo + parameters: [] + /todo/harvest/{id}/: + put: + operationId: todo_harvest_update + description: '' + parameters: + - name: data + in: body + required: true + schema: + $ref: '#/definitions/Harvest' + responses: + '200': + description: '' + schema: + $ref: '#/definitions/Harvest' + tags: + - todo + patch: + operationId: todo_harvest_partial_update + description: '' + parameters: + - name: data + in: body + required: true + schema: + $ref: '#/definitions/Harvest' + responses: + '200': + description: '' + schema: + $ref: '#/definitions/Harvest' + tags: + - todo + parameters: + - name: id + in: path + description: A unique integer value identifying this pack. + required: true + type: integer /todo/recursive/: get: operationId: todo_recursive_list @@ -1669,6 +1723,17 @@ definitions: minLength: 1 todo: $ref: '#/definitions/Todo' + Harvest: + type: object + properties: + size_code: + title: Size code + type: string + enum: + - '50' + - '100' + - '200' + readOnly: true TodoRecursive: required: - title