CUSTOM PRINT LIST:REFERENCE

30 views
Skip to first unread message

Ayron Rangel

unread,
May 22, 2018, 10:43:33 AM5/22/18
to web2py-users
Guys,

How can i custom print the list:reference <table> ??? I try to print the list reference and appears like this: [9L, 10L] not Item 9 - Pencil ; Item 10 - erase

In my case i have this:
model:
Field('item', 'list:reference itens')

view:
{{for row in results:}}
    {{=row.item}}

Anthony

unread,
May 22, 2018, 11:20:11 AM5/22/18
to web2py-users
Try:

{{for row in results.render():}}

Also, make sure you specify the "format" argument when defining the db.items table. As long as you do that, the "list:reference items" field will get a default "represent" attribute that will use the "format" argument to generate a list of items. The "represent" attribute will be used by the .render() method to transform the list of integer IDs stored in the field.

Anthony

Ayron Rangel

unread,
May 22, 2018, 11:53:31 AM5/22/18
to web2py-users

Anthony, 

its works!!!

Ayron Rangel

unread,
May 22, 2018, 12:26:00 PM5/22/18
to web2py-users
Anthony,

It's possible to convert to str()???? How can i do this?? 

{for x in item.render():}}
     <td style="width: 251px;">{{=x.item}}</td>
{{pass}}

Anthony

unread,
May 22, 2018, 1:50:33 PM5/22/18
to web2py-users
On Tuesday, May 22, 2018 at 12:26:00 PM UTC-4, Ayron Rangel wrote:
Anthony,

It's possible to convert to str()???? How can i do this?? 

{for x in item.render():}}

The .render() method is for Rows objects, not for an individual field value. The default "represent" function for a list:reference field will produce a string of comma-separated items, like "Item A, Item B, Item C". If you want that back in a Python list, you could do:

{{for element in item.split(', '):}}

Alternatively, you could create a custom "represent" function that generates the list that you want (or it could even generate a set of TD's containing the items).

Anthony
Reply all
Reply to author
Forward
0 new messages