[reportlab-users] how can i save PDF report into django model

Asif Jamadar asif.jamadar at rezayat.net
Wed Jun 22 01:23:48 EDT 2011


How can I save the dynamically generated PDF report into separate django model (database) as file.

I created model called 'Reports', in this model I defined a FileField.

In models.py

Class Report(models.Model):

file = models.FileField(upload_to='uploads/documents)'


In views.py

def report(request):

response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment;filename=ANALYSIS_REPORT.pdf'
buffer = StringIO()
doc = SimpleDocTemplate(response)
...................................................................
....................................................................
doc.build(document)
pdf = buffer.getvalue()

myfile = ContentFile(pdf)
m = Report()
m.file.save('test.pdf', myfile)
return response

But the above code saves the EMPTY report. So any advice on how to save the generated PDF report in django model

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20110622/94e9ca56/attachment.html>


More information about the reportlab-users mailing list