Exemplo n.º 1
0
class RemakeListSerializer(ModelSerializer):
    movie = MovieSerializer()
    user = UserSerializer()

    class Meta:
        model = models.Remake
        fields = ('id', 'title', 'movie', 'user', 'is_open')
        depth = 1
Exemplo n.º 2
0
class RemakeDetailSerializer(ModelSerializer):
    movie = MovieSerializer()
    user = UserSerializer()
    characters = CharacterSerializer(many=True)

    class Meta:
        model = models.Remake
        fields = '__all__'
        depth = 1
Exemplo n.º 3
0
    def put(self, request, pk, format=None):
        try:
            movie = Movie.objects.get(pk=pk)
            data = request.data
            count=0

            for gnr in data["genre"]:
                count = count + 1
                Genre.objects.get_or_create(title=gnr)

            if count == 0:
               return Response({"Movie Genres NOT present in the Json ***"}, status=status.HTTP_404_NOT_FOUND)

            serializer = MovieSerializer(movie, data=request.DATA)
            if serializer.is_valid():
                serializer.save()
                return Response(serializer.initial_data)
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
        except Movie.DoesNotExist:
            return Response({"Movie key: "+pk+" NOT present in the DB ***"}, status=status.HTTP_404_NOT_FOUND)
Exemplo n.º 4
0
    def post(self, request, format=None):

        data = request.data
        count=0

        for gnr in data["genre"]:
            count = count + 1
            Genre.objects.get_or_create(title=gnr)

        if count == 0:
           return Response({"Movie Genres NOT present in the Json ***"}, status=status.HTTP_404_NOT_FOUND)

        try:
            movie_name = data["name"]
            director_name = data["director"]
            Movie.objects.get(name=movie_name, director=director_name)
            return Response({"[Movie,Director]: ["+movie_name+","+director_name+"] is Already present in the DB ***"}, status=status.HTTP_302_FOUND)
        except Movie.DoesNotExist:
            serializer = MovieSerializer(data=data)
            if serializer.is_valid():
                serializer.save(owner=self.request.user)
                return Response(serializer.initial_data, status=status.HTTP_201_CREATED)
            return Response(serializer._errors, status=status.HTTP_400_BAD_REQUEST)