def update(self, request, id): # Method : PUT # Update a record queryset = self.get_detail(id) serializer = MessSerializer(queryset, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response(serializer.data) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request): # method: POST # Add details about Mess parsers_class = (FileUploadParser, ) file = request.FILES["profile_img"] print(file) serializer = MessSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def retrieve(self, request, id): # Method: GET # Return data about particular mess queryset = self.get_detail(id) serializer = MessSerializer(queryset) return Response(serializer.data)
def get(self, request): # method: GET # Return about Mess queryset = Mess.objects.all() serializer = MessSerializer(queryset, many=True) return Response(serializer.data)