I want to post to an endpoint from within a CBV and retrieve the response (in order to access the id of the created resource). I've had a look at How to programmatically call a Django Rest Framework view within another view? but cannot find how to send field values through with the request object. request.data is immutable, and passing kwargs through doesn't seem to be doing anything:
from app.views import OtherViewSet
class NewViews(APIView):
def post(self, request, *args, **kwargs):
# kwargs value here is {'field1':1, 'field2':2...}
view_func = OtherViewSet({'post':'create'})
response = view_func(self.request, *args, **kwargs).data
Although the kwargs contains the field values (set through several url named groups), the response always looks like:
{'field1': ['This field is required'], 'field2':['This field is required...
What am I doing wrong? Thanks all :)
Edit: Once I've got the ID of the created resource, I want to retrieve the resource as rendered by a particular (custom) format (I don't want to return the response object above).