[Django]-Django rest framework reverse relation field data omitted from validated_data

2👍

Since you followed the example provided in the api-guide and it works in shell I think that the data is not being sent properly.

Django Rest Framework uses APIClient for testing which is based on Django’s Test Client

If you don’t provide a content type the default value is multipart/form-data

If you don’t provide a value for content_type, the values in data will be transmitted with a content type of multipart/form-data. In this case, the key-value pairs in data will be encoded as a multipart message and used to create the POST data payload.

You will need to explicitly specify the format of the data as json:

response = self.client.post('/api/qnr/', data=qnr2, format='json')
👤AKS

Leave a comment