I'm creating a website with a list of candidates where staff members can increment the grade of candidates by clicking in validate.
I would like to increment the value of grade when I click on validate in the modal. It works because I can see in the admin panel that the grade of the candidate has been incremented but it does not redirect me in the list of candidates that was before.
How can I do to redirect to the list of candidates that was before ?
Here is the template displaying the list of candidates and the script displaying the modal :
<table id="students-table" class="table">
<thead>
</thead>
<tbody>
{% for student in student_list %}
<tr>
<td>
<button type="button" class="validate-student bs-modal btn btn-sm btn-primary"
data-form-url="{% url 'students:validate_grade' student.pk %}">
<span class="fa fa-eye"></span>
</button>
</td>
</tr>
{% endfor %}
</tbody>
<script type="text/javascript">
$(function () {
$(".validate-student").each(function () {
$(this).modalForm({ formURL: $(this).data("form-url")});
});
});
Here is the modal :
{% load widget_tweaks %}
<form method="POST" action="">
{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"><strong>{{ student.user.firstname }} {{ student.user.lastname
}}</strong></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Are you sure to validate this candidate ? ?
</p>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success">Validate</button>
</div>
Here is the view :
def validate_grade(request, pk):
context ={}
obj = get_object_or_404(Student, id = pk)
if request.method =="POST":
obj.grade_registration += 1
obj.save()
return HttpResponseRedirect(reverse('list_student', args=[1945]))
return render(request, "students/validate_student.html", context)