1๐
[UPDATE]: Something like that in your HTML
<div class="table-responsive">
<table class="..." >
<thead>
...
</thead>
<tbody>
{% for linea in lineas_de_reporte %}
<tr>
...
<td>
<form action="{% url 'view_name' %}" method="GET">
<input type="hidden" name="linea-id" value="{{ linea.id }}" />
<input type="submit" name="submit-issue-solved" value="Submit" />
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
Yes, this can happen with Django only (and with jQuery if you like).
You should alter the ISSUE RESOLVED?
column to a form where each cell (using the {% for %}
loop, of course) will contain two radio buttons (Yes
and No
), a hidden one (with the value of a unique key. I guess SOSS
is unique accross your db table?) and a submit button next to the radio ones.
Then, that form should submit itself (determined via the action={% url 'a_view_name_here' %}
attribute) to a url
and handled by a view
. Inside that view you can get the value, user selected (depending on the method used, i.e request.GET.get('issue_resolved')
or request.POST.get('issue_resolved')
) and in the same way the value of the unique value (i.e SOSS
).
Finally, youโll make a query to the db to get the TechnicalValidationSystem
with that SOSS
and update its issue_resolved
boolean value (like this:
def issue_resolved(request):
# if GET data contain a key named 'linea-id'...
if request.GET.get('linea-id'):
# ... this means that user clicked on the submit button
# get the id of linea
linea_id = request.GET.get('linea-id')
# fetch object from db, based on that id (aka pk)
linea = TechnicalValidationSystem.objects.get(id=linea_id)
# change its attribute to True
linea.issue_resolved = True
# update db with the new value
linea.save(update_fields=['issue_resolved'])
return render(request, 'template/to/the/table.html', context_here)