I have 2 buttons accept and decline in my requests.html when ever accept is clicked the request_status in my database should change to True and when decline is clicked it should change to False. My problem is that nothing happens when either of these two buttons are clicked.I am using query strings to retrieve the the wanted column from the database.
views.py:
def requests_leave_days(request, **kwargs):
if request.method == 'POST':
leaving_request = TimeOffRequest.objects.get(id=kwargs['request_id'])
if 'accept_request' in request.POST:
leaving_request.request_status = True
leaving_request.save()
count = {'accepted': 0, 'declined': 0, 'pending': 0}
accepted = TimeOffRequest.objects.all().filter(request_status='True')
refused = TimeOffRequest.objects.all().filter(request_status='False')
pending = TimeOffRequest.objects.all().filter(request_status=None)
#counting the number of refusals, acceptions and pending in the database
for acceptions in accepted:
count['accepted'] += 1
for refusal in refused:
count['declined'] += 1
for pending in pending:
count['pending'] += 1
return request.user.is_manager(
render(request, 'managers/requests.html',
{ 'accepted' : accepted,
'declined' : refused,
'pending' : pending,
'employees': User.objects.all(),
'workingperiods' : WorkPeriod.objects.all(),
'count' : count}),
redirect('news')
)
requets.html:
<div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Naam</th>
<th scope="col">E-mail</th>
<th scope="col">Telefoonnummer</th>
<th scope="col">Datum</th>
</tr>
</thead>
<tbody>
{% for requests in pending %}
{% for employee in employees %}
{% if requests.user_id == employee.id %}
<tr>
<th scope="row">{{ employee.id }}</th>
<td>
{{ employee.first_name | title }}
</td>
<td>{{ employee.email }}</td>
{% if employee.phone_number == None %}
<td>Geen</td>
{% else %}
<td>{{ employee.phone_number }}</td>
{% endif %}
{% for workday in workingperiods %}
{% if workday.id == requests.id %}
<td>{{ workday.start_time |date:"d F, Y"|lower }} - {{ workday.end_time |date:"d F, Y"|lower }}</td>
{% endif %}
{% endfor %}
<td><a href="{% url "requests" request_id=requests.id %}"><button method="POST" type="submit" name="accept_request" class="btn btn-dark" style="color: green;">Accepteren</button></a></td>
<td><a href="{% url "requests" request_id=requests.id %}"><button name="decline_request" type="button" class="btn btn-dark" style="color: red;">Weigeren</button></a></td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</tbody>
</table>
</div>