I need to add an extra parameter to the request.DATA. In this case the variable opentok_session needs to fill the field opentok_sessionid on the startCallSerializer
Im sending (tutorID, studentID)
need to save
(tutorID, studentID, opentok_sessionid)
if i try doing
post_values = request.POST.copy()
post_values['opentok_sessionid'] = opentok_session
it adds the value as expected but wont validate using serializers.is_valid() if empty POST is sent.
so i need to find a better way to save the value opentok_session and return opentok_sessionid
Thanks in advance for your help.
views.py
@api_view(['POST'])
def startCall(request):
if request.method == 'POST':
API_KEY = '00000'
API_SECRET = '000000000000000'
OTSDK = OpenTokSDK.OpenTokSDK(API_KEY, API_SECRET)
opentok_session = str(OTSDK.create_session().session_id)
serializer = startCallSerializer(data=post_values)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Views.py
class startCallSerializer(serializers.ModelSerializer):
class Meta:
model = call
fields = ('tutor', 'billed','opentok_sessionid')
exclude = ('tutor','billed')