I am using ajax to send data into a django view with data coming in via request.POST. I am posting the model field that needs to be updated as well as the model value. I just need to know how to use the field name variable I extract from request.POST['field_name'] so I can set the field in the model. Here is my code.
field_name = request.POST["field_name"]
field_value = request.POST["field_value"]
member_id = get_member_session(request).id
try:
member = Members.objects.get(id=member_id)
except:
status="ERROR-USER-DOES-NOT-EXIST"
return json_status(status)
try:
member.field_name=field_value
member.save()
return json_status('OK')
except:
status = "USER_SAVE_ERROR"
return json_status(status)
member.field_name is obviously not right. Do I need to use eval(field_name) or something like that? I would prefer not to if possible.
Many thanks
Rich