I am attempting to user ReportLab with Django to make a report
displaying my data in a tabular format.

An example model is:

class Vehicle(models.Model):
    ve_name = models.CharField(max_length=20)
    ve_type = models.CharField(max_length=20)

My report generating view a copy of the example in the ReportLab
docs.  I have marked my sticking point with '''

def testX(request):
    # Our container for 'Flowable' objects
    elements = []
    # A large collection of style sheets pre-made for us
    styles = getSampleStyleSheet()

    # A basic document for us to write to 'rl_hello_table.pdf'
    doc = SimpleDocTemplate('rl_hello_table.pdf')

    elements.append(Paragraph("Vehicle Summary", styles['Title']))

    vehicles = Vehicle.objects.all()

'''the question is how to modify the following lines to read the data
from vehicles rather than use the hard coded data shown in the
example'''

     data = [['Caves',         'Wumpus Population'],
        ['Deep Ditch',    50],
        ['Death Gully',   5000],
        ['Dire Straits',  600],
        ['Deadly Pit',    5],
        ['Conclusion',    'Run!']]

'''after that, I think I can sort out the following'''
    # First the top row, with all the text centered and in Times-Bold,
    # and one line above, one line below.
    ts = [('ALIGN', (1,1), (-1,-1), 'CENTER'),
        ('LINEABOVE', (0,0), (-1,0), 1, colors.purple),
        ('LINEBELOW', (0,0), (-1,0), 1, colors.purple),
        ('FONT', (0,0), (-1,0), 'Times-Bold'),

# The bottom row has one line above, and three lines below of
# various colors and spacing.
        ('LINEABOVE', (0,-1), (-1,-1), 1, colors.purple),
        ('LINEBELOW', (0,-1), (-1,-1), 0.5, colors.purple, 1, None,
None, 4,1),
        ('LINEBELOW', (0,-1), (-1,-1), 1, colors.red),
        ('FONT', (0,-1), (-1,-1), 'Times-Bold')]

    # Create the table with the necessary style, and add it to the
    # elements list.
    table = Table(data, style=ts)
    elements.append(table)

Can anyone give me a push in the right direction?  Thanks for any
help.

Mike

--

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=.


Reply via email to