4👍
✅
You need to return serializer.data
instead of serializer.validated_data
.
Have a look at the updated code for ReservationViewSet
:
class ReservationViewSet(CreateModelMixin, GenericViewSet):
serializer_class = ReservationSerializer
queryset = Reservation.objects.all()
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response(status=status.HTTP_201_CREATED, data=serializer.data)
the data
property is meant to translate the model instance into the Python native dictionary type. Python Dictionary can be serialized as a JSON Response.
Source:stackexchange.com