Try using: text = item.category.name
and text = '%s' % item.subject.name Rather than sending the entire FK field to ReportLab. I don't necessarily see a problem with this logic in your view, as you're just generating a file response. If it doesn't feel right, you can throw this logic into a utility package (ie: something like reports.py) and reference it from your view. Cheers On Nov 17, 3:55 pm, Victor Hooi <victorh...@gmail.com> wrote: > Hi, > > I'm trying to use ReportLab to produce a PDF output for one of my > views. > > My first question is - at the moment, I'm building up the PDF inside > my view. Is this really the recommended way of doing it? It's like > I've got presentation code inside my view (controller). Isn't there a > cleaner way of doing it, or going from a template to PDF somehow? (I > know ReportLab offers a commercial package using RML templates, > however I was hoping for an opensource/free method). > > Second question, I have a model with several FK fields. E.g. > > class Article(models.Model): > category = models.ForeignKey(Category) > subject = models.ForeignKey(Subject) > > Both the category and subject classes have fields called "name", and > __unicode__ methods defined which return name. > > I'm trying to refer to these fields in my PDF output. I have a list of > items in article_list (i.e. queryset): > > for item in article_list: > text = item.category > category = Paragraph(text, styles['Heading2']) > story.append(category) > > text = '%s' % item.subject > subject = Paragraph(text, styles['Heading3']) > story.append(subject) > > When I try to run this code, I get: > > 'Category' object has no attribute 'split' > > and the same error with subject, obviously, once it gets to that bit > of the code. > > Any idea why this might be, or how to fix it? Any help is much > appreciated. > > Cheers, > Victor -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.