我有一个表格,在提交时我发送帖子数据:
exset 349
exset 495
exset 344
reps 11
reps 22
reps 33
weight 1
weight 2
weight 3
在视图中我想保存它:
exset 349
reps 11
weight 1
exset 495
reps 22
weight 2
exset 344
reps 33
weight 3
但在数据库中我有3行包含最后一个数据。是否可以创建一个循环来保存所有3部分数据?
我使用jquery发送查看请求:
$("form").submit(function() {
$(".ex_set").each(function() {
var array = $("input", this).serializeArray();
//console.log(array);
//alert(json.exset_id);
});
});
以下是我的观点:
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)