I am fetching data from RetrieveAPIView I want to overwrite it.
class PostDetailAPIView(RetrieveAPIView):
queryset = Post.objects.all()
serializer_class = PostDetailSerializer
lookup_field = 'slug'
http://127.0.0.1:8000/api/posts/post-python/
it return me result
{
"id": 2,
"title": "python",
"slug": "post-python",
"content": "content of python"
}
I want to overwrite this with some extra parameters like
[
'result':
{
"id": 2,
"title": "python",
"slug": "post-python",
"content": "content of python"
},
'message':'success'
]
Ok, in comment I made wrong call, you want to overwrite get() method of your View.
class PostDetailAPIView(RetrieveAPIView):
queryset = Post.objects.all()
serializer_class = PostDetailSerializer
lookup_field = 'slug'
def get(self, request, slug):
post = self.get_object(slug)
serializer = PostDetailSerializer(post)
return Response({
'result': serializer.data,
'message': 'success'
})
Notes
1. I names second argument of get function slug because it's your lookup_field, but it should be name you used in urls.
2. You could instead overwrite retrieve() function
3. This is answer specific for your question, you should also read this answer