Incorrect model in subtask serializer and add PUT PATCH for subtask

This commit is contained in:
sosokker 2023-11-28 01:20:01 +07:00
parent f9e1250c56
commit cfccebf189
2 changed files with 16 additions and 2 deletions

View File

@ -107,4 +107,4 @@ class SubTaskSerializer(serializers.ModelSerializer):
def create(self, validated_data):
# Create a new task with validated data
return Todo.objects.create(**validated_data)
return Subtask.objects.create(**validated_data)

View File

@ -130,7 +130,8 @@ list=extend_schema(
class SubTaskViewset(viewsets.GenericViewSet,
mixins.CreateModelMixin,
mixins.DestroyModelMixin,
mixins.ListModelMixin):
mixins.ListModelMixin,
mixins.UpdateModelMixin):
queryset = Subtask.objects.all()
permission_classes = (IsAuthenticated,)
@ -173,6 +174,19 @@ class SubTaskViewset(viewsets.GenericViewSet,
return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def partial_update(self, request, *args, **kwargs):
"""Update a subtask."""
try:
instance = self.get_o
serializer = self.get_serializer(instance, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
self.perform_update(serializer)
return Response(serializer.data)
except Exception as e:
return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class RecurrenceTaskViewSet(viewsets.ModelViewSet):
queryset = RecurrenceTask.objects.all()
serializer_class = RecurrenceTaskSerializer