0

We have the following code working for receiving JSON strings for one value:

def spo2_new(request):
  if request.method == 'POST':
     data = {}
     fields = request.POST.copy()
     spo2 = SPO2(user=User.objects.get(pk=1), spo2=fields['value'], time=fields['datetime'])
     spo2.save()
     data['succes'] = True
    return JSONResponse(data)
raise Http404

The JSON string format POST is:

value=102.3&datetime=2011-05-04%2021:13:11

My question would be, how can we do the same for sending multiple "values" (with the datetime for each value) instead of sending each value individually?

Update 1: Since time interval is known, could I just send the values array and just the initial datetime?

2 Answers 2

1

Since you are already using JSON why don't simply send a JSON-encoded array of values [(timestamp, value)]?

POST: values=[[datetime1, value1],[datetime2,value2],...]

Sign up to request clarification or add additional context in comments.

Comments

0

Within your page you can build an array and post those values manually as stated below:

values=[[datetime1, value1],[datetime2,value2]]

Or you could loop over all items and build the list:

$.each($('.datetime'), function(i, item){
    datetime_values.append($(item).value());
}

Within your view you can get a list of values passed as:

request.POST.getlist('datetime')

1 Comment

I think it has to be built manually since the server is an Arduino board sending the data to a web server (the client in this case and running Django). So the string would look something like this? -> values=[[2011-04-05%2021:04:05, 132.4],[2011-04-05%2021:04:21, 151],[2011-04-05$2021:04:35, 123]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.