Rohit Thapliyal
Rohit Thapliyal

Reputation: 27

Adding response for post in ModelViewset

I have to provide a DB status response (which tells if the serializer gets stored or not) after a POST request in ModelViewSet. Please help me perform that in the view.

from django.shortcuts import render
from .models import Booking
from rest_framework import viewsets
from .serializers import BookingSerializer

class BookingViewSet(viewsets.ModelViewSet):
    queryset = Booking.objects.all()
    serializer_class = BookingSerializer

Upvotes: 0

Views: 812

Answers (1)

Just a 200 or 201 will do and django already handles this. If you want to override the response message

Here is a snippet

 from rest_framework.response import Response
 from rest_framework import status


 def create(self, request, *args, **kwargs):
     ...
     return Response({'success': 'Data successfully submitted'}, status=status.HTTP_200_OK)

Upvotes: 1

Related Questions