[Answered ]-How to include a dropdown query into a HttpResponse view

1👍

This is fairly simple. Simply include the get request and give a name to the form you intend to get the selection from i.e.

def ConvertToExcelView(request):
    details = request.GET.get('s_details') #Assuming the form name is s_details
    queryset = (Q(student__klass__name__exact = details))
    response = HttpResponse(content_type='text/csv')
    writer = csv.writer(response)
    writer.writerow([('name'), ('adm'),('form'),('stream') ])
    for member in Marks.objects.filter(queryset).distinct().filter(student__school__name=request.user.school).values_list('student__name',     'student__adm', 'student__klass__name', 'student__stream__name':
        writer.writerow(member)       
    response['Content-Disposition'] = 'attachment; filename="members.csv"'
    return response

This will work like charm.
Revert if there are explanations you need.

👤Ptar

Leave a comment