I have the following data coming in to a Django view using the Django REST framework -
{'varmst_starttype': 'SCH_DATE', 'varmst_offsets': '0000SUNDAY1', 'owner_name': 'Operations', 'varmst_publish': 'N', 'varmst_calc': 'Y', 'varmst_public': 'Y', 'varmst_desc': None, 'varmst_name': 'var_date ', 'varmst_readonly': 'N', 'varmst_value': 20140911, 'varmst_startdt': datetime.datetime(1899, 12, 30, 0, 0), 'varmst_lstchgtm': datetime.datetime(2014, 9, 10, 22, 0, 28), 'varmst_id': 1867, 'varmst_lstval': None, 'varmst_startcal': 0, 'varmst_type': 3}
What I want to do is use the key value on 'owner_name' to get the 'id' by going -
ownername = request.DATA['owner_name']
ownerid = Owner.objects.filter(owner_name=ownername).values_list('owner_id')[0]
I then want to remove the 'owner_name': 'Operations'
and replace it with 'owner_id': 235
When I try to just get a response on ownername I get the following error -
list indices must be integers, not str
This is my view that I'm working off of -
def put(self, request, format=None):
data = request.DATA
data.update({'owner_id': 786})
return HttpResponse(data)
I've updated to remove the serializer as the issue is before I even get to serialization but with trying to modify the request data. Even on a simple trying to update the request.DATA I get errors. Using the above PUT I get the following -
'list' object has no attribute 'update'
Which makes sense because my understanding is that this is a dict. But according to this -
http://stackoverflow.com/questions/1024847/add-to-a-dictionary-in-python
The same process should work for a dict?
This attempt fails with the original Title of the question.
def put(self, request, format=None):
data = request.DATA
data.['owner_id'] = 786
return HttpResponse(data)