I have a form and when submit it i send post data:
exset 349
exset 495
exset 344
reps 11
reps 22
reps 33
weight 1
weight 2
weight 3
in view i want to save it like this:
exset 349
reps 11
weight 1
exset 495
reps 22
weight 2
exset 344
reps 33
weight 3
but in database i have 3 rows with last data. Is it possible to make a loop to save all 3 portion of data?
I use jquery to send request to view:
$("form").submit(function() {
$(".ex_set").each(function() {
var array = $("input", this).serializeArray();
//console.log(array);
//alert(json.exset_id);
});
});
Here is my view:
def TrackWkDay(request):
workout_log = Workout_log()
if request.method == 'POST':
workout_log.exset_id = request.POST.get('exset')
workout_log.weight = request.POST.get('weight')
workout_log.reps = request.POST.get('reps')
workout_log.save()
message = 'Data saved'
returned = {'message':message}
json = simplejson.dumps(returned)
mimetype = 'application/json'
return HttpResponse(json, mimetype)
else:
return HttpResponse(status=400)