Reputation: 29
here is my code
def user_invoice_pdf(request,queryset):
template_path = 'user/order_details.html'
context = {'product':queryset}
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="invoice.pdf"'
template = get_template(template_path)
html = template.render(context)
pdf = render_to_pdf(template_path,context)
if pdf:
receipt_file = File(BytesIO(pdf.response))
print(receipt_file,'receipt_file')
invoice = InvoiceData(user_info=request.userinvoie=receipt_file)
invoice.save()
else:
return response
return True
Upvotes: 0
Views: 67
Reputation: 29
try this
file_name = first_name
file_name2 = file_name+'.'+ "pdf"
user_invoice_obj=Modelsname(user=request.user,order_product=queryset)
user_invoice_obj.save()
user_invoice_obj.invoice.save(file_name2, File(BytesIO(pdf)))
Upvotes: 1