Hello Everyone I am getting Attribute Error. I have one Django based webpage where I am using Django filter to search user result and trying to implement functionality for download filtered result only in order to achieve this I am trying to pass Filter class, in my existing download views. (Earlier my download view is responsible to download all model-based data). My code is
```
from .models import *
import django_filters
class ShiftChangeFilter(django_filters.FilterSet):
id = django_filters.NumberFilter(label="DSID")
class Meta:
model = ShiftChange
fields = ['ConnectID', 'EmailID','id','SerialNumber','Project_name','']
```
Hello Everyone I am getting Attribute Error. I have one Django based webpage where I am using Django filter to search user result and trying to implement functionality for download filtered result only in order to achieve this I am trying to pass Filter class, in my existing download views. (Earlier my download view is responsible to download all model-based data). My code is
from .models import *
import django_filters
class ShiftChangeFilter(django_filters.FilterSet):
id = django_filters.NumberFilter(label="DSID")
class Meta:
model = ShiftChange
fields = ['ConnectID', 'EmailID','id','SerialNumber','Project_name','']
My view responsible to download xls file:
from django.utils import timezone
now_aware = timezone.now()
import xlwt,openpyxl
def exportgenesys_data(request):
allgenesys = ShiftChange.objects.all()
genesys_filter = ShiftChangeFilter(request.GET,queryset=allgenesys )
allgenesys2 = genesys_filter.qs
print(‘download:’,allgenesys2 )
response = HttpResponse(content_type='application/ms-excel')
response['Content-Disposition'] = 'attachment; filename="Genesys_ShiftTiming.xls"'
wb = xlwt.Workbook(encoding='utf-8')
ws = wb.add_sheet('GenesysShiftChange Data') # this will make a sheet named Users Data
# Sheet header, first row
row_num = 0
font_style = xlwt.XFStyle()
font_style.font.bold = True
columns = ['id', 'ConnectID', 'Shift_timing', 'EmailID', 'Vendor_Company', 'Project_name', 'SerialNumber',
'Reason', 'last_updated_time']
for col_num in range(len(columns)):
ws.write(row_num, col_num, columns[col_num], font_style) # at 0 row 0 column
# Sheet body, remaining rows
font_style = xlwt.XFStyle()
rows = allgenesys2.values_list('id', 'ConnectID', 'Shift_timing',
'EmailID', 'Vendor_Company', 'Project_name',
'SerialNumber', 'Reason', 'last_updated_time')
for row in rows:
row_num += 1
for col_num in range(len(row)):
ws.write(row_num, col_num, row[col_num], font_style)
wb.save(response)
return response
When I am clicking on download button I am getting all the records.