def movie_list(request): """ List all 'MovieDetails', or create a new 'MovieDetail'. """ if request.method == 'GET': movie_details = MovieDetails.objects.all() serializer = MovieSerialzers(movie_details, many=True) return Response(serializer.data) elif request.method == 'POST': serializer = MovieSerialzers(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def movie_detail(request, name): """ Retrieve, update or delete a 'MovieDetails' instance. """ try: movie_details = MovieDetails.objects.filter(name__contains=name) except MovieDetails.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = MovieSerialzers(movie_details, many=True) return Response(serializer.data) elif request.method == 'PUT': serializer = MovieSerialzers(movie_details, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) elif request.method == 'DELETE': movie_details.delete() return Response(status=status.HTTP_204_NO_CONTENT)