如何将下拉查询包含到 HttpResponse 视图中
How to include a dropdown query into a HttpResponse view
我想在通过下拉选择过滤器后将模型的内容转换为 excel。这是视图。
def ConvertToExcelView(request):
response = HttpResponse(content_type='text/csv')
writer = csv.writer(response)
writer.writerow([('name'), ('adm'),('form'),('stream') ])
for member in Marks.objects.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
有什么方法可以将其合并到视图中吗????
query = request.GET.get('view_classes')
if query:
queryset = (Q(student__klass__name__icontains = query))
return render(request,'students_marks.html',all_mark_results)
如果我对此不清楚,请询问更多说明。
这很简单。只需包含获取请求并为您打算从中获取选择的表单命名,即
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
这会很有效。
如果您需要解释,请回复。
我想在通过下拉选择过滤器后将模型的内容转换为 excel。这是视图。
def ConvertToExcelView(request):
response = HttpResponse(content_type='text/csv')
writer = csv.writer(response)
writer.writerow([('name'), ('adm'),('form'),('stream') ])
for member in Marks.objects.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
有什么方法可以将其合并到视图中吗????
query = request.GET.get('view_classes')
if query:
queryset = (Q(student__klass__name__icontains = query))
return render(request,'students_marks.html',all_mark_results)
如果我对此不清楚,请询问更多说明。
这很简单。只需包含获取请求并为您打算从中获取选择的表单命名,即
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
这会很有效。 如果您需要解释,请回复。