I am working on a result processing website and I've been trying to update multiple fields in each row of table. User should be able to input updated CA Score and EXAM Score values and it should update each student's CA Score and EXAM Score values which has been submitted. image of page <https://drive.google.com/file/d/1YRh8IK-m7r8IuYhradrX5ZQ_gjE5WAa_/view?usp=sharing>
Someone ask same question here <https://stackoverflow.com/questions/43559164/how-to-get-multiple-values-from-a-template-and-update-multiple-rows-in-a-table> trying to update a single field. I tried to work with the solution provided there but was unable to make it suit my need template <form action="" method="post"> {% csrf_token %} {% for student in students %} <tr> <td>{{ student.id_number }}</td> <td> <input type="number" value="{{ student.ca }}" name="student_{{ student.id }}"> </td> <td> <input type="number" value="{{ student.exam }}" name="student_{{ student.id }}"> </td> </tr> {% endfor %} <tr> <td><input type="submit" value="Save"></td> </tr> </tbody> </table> </form> view def add_score_for(request, id): if request.method == 'GET': students = TakenCourse.objects.filter( course__allocated_course__lecturer__pk=request.user.id).filter(course__id=id ) context = { "students":students} return render(request, 'result/add_score_for.html', context) if request.method == 'POST': data = request.POST.dict() data.pop('csrfmiddlewaretoken', None) for i in data.items(): obj = TakenCourse.objects.get(id=i[0].split("_")[1]) if not str(obj.ca) == str(i[1]): # if i do i[2] trying to get for exams it raise 'tuple index out of range' obj.ca = i[1] obj.save() Thanks in advance. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0db4c048-f712-4a3d-9670-abe5dbca3d56%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.