• 1000 * models.py
задача класса (models.Model):
Name=models.CharField(max_length=50,null=False,blank=True)
Image1=models.FileField(blank=True, default="",
upload_to="media/images",null=True)
views.py
класс TaskViewSet (viewsets.ViewSet):
def list(self,request):
try:
output = io.BytesIO()
workbook=xlsxwriter.Workbook(output)
worksheet=workbook.add_worksheet()
product=Task.objects.all()
for pro in product:
url=pro.Image1.url
image_data=BytesIO(urlopen(url).read())
worksheet.insert_image(1,1,url,{'image_data',image_data})
workbook.close()
output.seek(0)
response = HttpResponse(output.read(),content_type='application/ms-excel')
response['Content-Disposition']='attachment; filename="users.xls"'
return response
except Exception as error:
traceback.print_exc()
return Response({"message": str(error), "success": False}, status=status.HTTP_200_OK)