web2py SQLTABLE - How can I transpose the table?

Tags: python web2py
By : Neveen
Source: Stackoverflow.com
Question!

I am using:

rows = db(db.member.membership_id==request.args[0]).select(db.member.membership_id,
    db.member.first_name,
    db.member.middle_name,
    db.member.last_name,
    db.member.birthdate,
    db.member.registration_date,
    db.member.membership_end_date)

rows.colnames = ('Membership Id', 'First Name', 'Middle Name', 'Last Name', 
    'Birthday Date', 'Registration Date', 'Membership ending Date')
table = SQLTABLE(rows, _width="100%")

Now I want to transpose the table, how can I do this?

By : Neveen


Answers

Try this:

rows=db(query).select(*fields).as_list()
if rows:
   table=TABLE(*[TR(TH(field),*[TD(row[field]) for row in rows]) \ 
       for field in row[0].keys()])
else:
   table="nothing to see here"
return dict(table=table)
By : mdipierro


This video can help you solving your question :)
By: admin