Exporting foreign keys as represented value

55 views
Skip to first unread message

joe

unread,
Jul 24, 2012, 9:59:15 AM7/24/12
to web...@googlegroups.com
Hello

I am working with xlwt and trying to export a table of mine into a .xls file.  This table contains some foreign keys, and they are being exported as the id of the other table rathan than the 'name' field, which is what I want to display.  I define the foreign key fields in the table like this:


Field('owner', db.person, requires = IS_EMPTY_OR(IS_IN_DB(db, db.person, '%(name)s')), represent=lambda id, row: db.person(id).name if id else ' '),

Thanks!

Anthony

unread,
Jul 24, 2012, 10:36:22 AM7/24/12
to web...@googlegroups.com
How are you exporting the data? The export_to_csv_file() method, for example, takes a "represent" argument -- if set to True, it will use each field's "represent" attribute to convert the values before exporting.

Anthony

joe

unread,
Jul 24, 2012, 10:49:13 AM7/24/12
to web...@googlegroups.com
I am using xlwt to export the data (I want an excel file, and a bit more control over format).  I recently made it work, in about the most clumsy way possible (getting a row object from the referenced table, casting it into a string, and finding the substring that I want to display), but there has to be a simpler way.

Thanks!
-Joe Peacock

Anthony

unread,
Jul 24, 2012, 11:11:37 AM7/24/12
to web...@googlegroups.com
Can you show the code you are using to get the data from the db to xlwt?

Anthony
Reply all
Reply to author
Forward
0 new messages