I have a TABLE where im showing different bills of different clients:
And i have this code in my views.py:
@login_required
def descarga(request,id_factura):
selected_values = request.POST.getlist('factura')
if request.method == 'POST':
form = Factura.objects.filter(id__in=selected_values)
if form:
(...Styling of the Excell file...)
# write the header
header = ['Cliente', 'Fecha de Factura', 'Tipo de Factura', 'Numero de Factura', 'Descripcion', 'Subtotal', 'IVA', 'Precio']
for hcol, hcol_data in enumerate(header): # [(0,'Header 1'), (1, 'Header 2'), (2,'Header 3'), (3,'Header 4')]
sheet.write(0, hcol, hcol_data, font_size_style)
for facturas in form:
data = {
"Cliente": form.nombre_cliente,
"Fecha de Factura":form.fecha_factura,
"Tipo de Factura": form.tipo_Factura,
"Numero de Factura": form.numero_De_Factura,
"Descripcion": form.descripcion,
"Subtotal": form.importe_sin_iva,
"IVA": form.iva,
"Precio": form.importe_Total,
}
for column, key in enumerate(header, start=1):
sheet.write(1, column, str(data[key]), body_style)
response = HttpResponse(mimetype='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=report.xls'
response = render_to_response(context_instance = RequestContext(request, locals()), mimetype='application/vnd.ms-excel')
return response
This function DOwnloads the information of ONE bill into an Excel file. This function is attach to a button that IS NOT in the same template of the table, it´s in the template where the information of he bill is display (by clicking in "Ver" another template shows you the information in a nice format)
So now what i have to do is to place the button in the same page where the table is and export only the ones that are selected in the checkbox.
The question is: How do i tell the view to only export the ones that are checked? AND is this function going to work in the same way in this with as it works in the one wher i´m only showing the information of ONE bill.
This is the code that i have in my template:
{% for factura in facturas %}
<tr>
<td><i class="fa fa-file"> <a href="{% url 'ver_Factura' factura.pk %}">Ver</a></i>
<div class="checkbox">
<label>
<input type="checkbox">
</label>
</div>
</td>
<td>{{ factura.nombre_cliente }}</td>
<td>{{factura.numero_De_Factura }}</td>
<td>{{factura.fecha_factura }}</td>
</tr>
{% endfor %}
Any little help will be really appreciated. Thank you