コード例 #1
0
    def delete(self, request, *args, **kwargs):
        if not kwargs:
            return Response({"message": "Invalid URL"}, 400)

        genre, status = GetData(kwargs=kwargs,
                                db_model=Genre,
                                db_serializer=GenreSerializer,
                                serialized_output=False)
        if status != 200:
            return Response({"message": "Record not Found"}, 400)

        genre[0].delete()
        return Response({"message": "Record successfully deleted"},
                        status=status)
コード例 #2
0
    def put(self, request, *args, **kwargs):
        json_data = request.data
        if not (json_data and kwargs):
            return Response({"message": "Invalid Data/URL"}, 400)

        genre, status = GetData(kwargs=kwargs,
                                db_model=Genre,
                                db_serializer=GenreSerializer,
                                serialized_output=False)
        if status != 200:
            return Response({"message": "Record not Found"}, 400)

        genre, status = PostData(json_data, GenreSerializer, put_obj=genre[0])
        return Response(genre, status)
コード例 #3
0
 def get(self, request, *args, **kwargs):
     search_param = dict()
     pages = dict()
     page_filter = ['page', 'per_page']
     for key, value in request.GET.items():
         if key in page_filter:
             pages[key] = value
         else:
             search_param[key] = value
     genre, status = GetData(search_param=search_param,
                             kwargs=kwargs,
                             db_model=Author,
                             db_serializer=AuthorSerializer,
                             pages=pages)
     return Response(genre, status=status)