Similar question, but maybe simpler?
I have a table name which, for various reasons, isn't very human reader
friendly (crowner). I'd like to add a table attribute (e.g. print_name =
'Copyright Owners') to be used for table display instead of the table name
itself
Does that mean db.table._extra = {'print_name' : 'Copyright Owners'} or ???
If so, how do I access that attribute? db.table.['print_name'] ???
Thanks
On Sunday, April 22, 2018 at 3:15:03 AM UTC-7, xelomac wrote:
>
> I want to add a custom attribute so that I can decide which customwidget
> has to be used for a form field connected to that field.
> Example:
>
> db.define_table('person',
> Field('salutation', mycustomwidget='select2', label = T('Salutation'),
> requires=IS_IN_SET(GENDER), represent=lambda v, r: GENDER[v]),
> Field('first_name', label = T('First Name')),
> format = '%(last_name)s')
>
>
> I had no luck defining that custom attribute the way it is described in
> the book. How and and where would I define such a custom attribute
> 'mycustomwidget' for the table 'person' or even better for all tables?
>
> Adding attributes to fields and tables
>
> If you need to add custom attributes to fields, you can simply do this:
>
> 1
>
> db.table.field.extra = {}
>
> "extra" is not a keyword ; it's a custom attributes now attached to the
> field object. You can do it with tables too but they must be preceded by an
> underscore to avoid naming conflicts with fields:
>
> 1
>
> db.table._extra = {}
>
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/f7d701f7-81d5-4544-a77b-a2b4f397cfe2%40googlegroups.com.