I am trying to add an extra field auth_token in my table with the request.data but it is giving errors. The error is -
data['auth_token_id'] = auth_token
TypeError: list indices must be integers or slices, not str
My code is given below:
serializers.py
class AppSerializer(serializers.ModelSerializer):
class Meta:
model = ThirdPartyApps
fields = ('app_name', 'package_name', 'auth_token_id')
views.py
@api_view(['POST'])
def add_apps(request):
data = request.data
auth_token = request.META.get('HTTP_AUTHTOKEN', '')
data['auth_token_id'] = auth_token
serializer = AppSerializer(data=data, many=True)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
else:
return Response(serializer.errors)
I am looking for a way to pass extra data through the serializer.
I just want to add auth_token to my model like the request.data but it is giving this error -
data['auth_token_id'] = auth_token
TypeError: list indices must be integers or slices, not str