Как экспортировать текущие данные CSV из набора django-filter
view.py django-filter
def fourm(request):
data_list = FourmAproveCoWeb.objects.all()
data_filter = DataFilter2(request.GET, queryset=data_list)
return render(request, 'fourmlist.html', {'filter': data_filter})
filter.py
class DataFilter2(django_filters.FilterSet):
issue_date = django_filters.DateFromToRangeFilter()
qa_follow_up_date = django_filters.DateFromToRangeFilter()
class Meta:
model = FourmAproveCoWeb
fields = ['issue_date','pic_field','status','ecr','number_4m','qa_follow_up_date']
@ просмотреть функцию экспорта
Я хочу экспортировать в фильтр данных уже.это не работает
def export_as_csv(request):
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
data_list = FourmAproveCoWeb.objects.all()
data_filter = DataFilter2(request.GET, queryset=data_list)
writer = csv.writer(response)
writer.writerow(['PIC','Process'])
x = []
for i in data_filter.qs:
print(i.ecr)
writer.writerow([i.pic_field,i.process])
return response