views.py
def export(request):
print('start')
ourid = request.POST.getlist("terid")
queryset = Case_Info.objects.filter(id__in=list(map(int, ourid)))
Case_Detail = Case_Info_Resource()
print(ourid)
dataset = Case_Detail.export(queryset) # error in this line
response = HttpResponse(
dataset.xls, content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename="persons.xls"'
print('end')
return response
Ajax Script
$(document).ready(function () {
$('#Download').click(function () {
console.log("clicked!")
var list = [];
$("input:checkbox[name='checkbox']:checked").each(function () {
list.push($(this).val());
});
$('#Download').attr('disabled', 'disabled');
$.ajax({
url: '/Account_Manager/Download/',
type: 'POST',
data: {
'terid': list,
'csrfmiddlewaretoken': '{{csrf_token}}',
},
timeout: 30000,
traditional: true,
dataType: 'text',
success: function () {
alert("The best cricketers are: " + list.join(", "));
$('#Download').removeAttr('disabled');
}
});
});
});
What I am trying to do is pass several ids from the front end to the back and then export data from the database accordingly. everything is working fine till this following line.
dataset = Case_Detail.export(queryset)
after this line, it again reaches to the beginning of the function that results in the blank list that results in an empty excel file