コード例 #1
0
 def post(self, request):
     # Method: POST
     # Add menu for a given mess
     print(request.data)
     serializer = MenuSerializer(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)
コード例 #2
0
 def update(self, request, menu_id):
     # Method : PUT
     # Update a menu
     # @param: menu_id
     # @return:  Updated a record of menu
     queryset = self.get_detail(menu_id)
     serializer = MenuSerializer(queryset, data=request.data, partial=True)
     print(request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_200_OK)
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #3
0
 def get_data(self, request, menu_id):
     # Method: GET
     # @param: mess_id( !pass mess id to api endpoint)
     # @return: List all mess with that mess_id
     queryset = Menu.objects.filter(mess_id=menu_id)
     serializer = MenuSerializer(queryset, many=True)
     return Response(serializer.data)
コード例 #4
0
 def get(self, request):
     # Method: GET
     # Return mess menu
     queryset = Menu.objects.all()
     serializer = MenuSerializer(queryset, many=True)
     return Response(serializer.data, status=status.HTTP_200_OK)