user976518
user976518

Reputation: 21

web2py: how to download image with SQLTABLE

I'd like to know if it's possible use SQLTABLE to build up a list of images. Images are in a database table, but I don't want just a link to download.

Upvotes: 1

Views: 452

Answers (1)

You can do it in a number of ways:

First:

db.table.field.represent = lambda r, v: IMG(_src=URL('default',
                                                     'download',
                                                      args=v.field))

# where field is the field where your picture lives.

Second is using web2py virtual fields:

class MyVirtual(object):
    def photo(self):
        return IMG(_src=URL('default', 'download', args=self.table.field))

db.table.virtualfields.append(MyVirtual())

table = SQLTABLE(db(db.table).select())

Third is using extracolumns:

myextracolumns = [{'label': 'My Photo',
                   'content': lambda row, rc: IMG(_src=URL('default',
                                                           'download',
                                                            args=row.field))}]

table = SQLTABLE(rows, extracolumns=myextracolumns)

Upvotes: 2

Related Questions