Re: ReportLab and Django - templates? ; FK object has no attribute split
Hi Victor,
It really depends on complexity of your PDF. I needed to do
something similar some time ago and used ReportLab addon called "pisa"
and used standard Django template language to define the PDF contents.
You might want to take a look, it worked well enough for simple PDF pages.
Cheers
Jirka
On 18/11/2010, Victor Hooi <victorhooi@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-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home