[Answer]-Why does this view only grab the first value, not all the list values?

1👍

Because you exit the function with a return statement after processing only the first value:

for i in range(len(request.POST.getlist('examen'))):
    data = {
        'nombre_examen': request.POST.getlist('examen')[i],
        'credencial_miembro': request.POST['laboratorio_credencial']
    }
    print data
    medicina = examenlab_form(data)

    if medicina.is_valid():
        medicina.save()
        medicinas.append(medicina)
        messages.success(request, 'Alta Exitosa!')
    return HttpResponseRedirect('')

Move that return statement out of the loop. You should also just loop over the .getlist() call, no need to use induces here:

for exam in request.POST.getlist('examen'):
    data = {
        'nombre_examen': exam,
        'credencial_miembro': request.POST['laboratorio_credencial']
    }
    print data
    medicina = examenlab_form(data)

    if medicina.is_valid():
        medicina.save()
        medicinas.append(medicina)
        messages.success(request, 'Alta Exitosa!')

return HttpResponseRedirect('')

Leave a comment