Since you gonna import one homemade module anyway, why not just:
from applications.yourapp.modules.country import
country_names_as_a_list
db.define_table('shipping_info',
Field('countries', _requires=IS_IN_SET(country_names_as_a_list))
...
)
This way you don't force yourself to know something difficult (though
not that difficult if you really know widgets well).
On Oct7, 8:05pm, Jon Romero <[email protected]> wrote:
> ok, I've imported gluon.html but now it seems there is another
> different error.
>
> I am creating a country widget (it will display all countries in a
> dropdown box).
>
> So, in my db.py I have this:
> from applications.appname.modules.countries import *
> db.shipping_info.countries.widget = countries_widget
>
> and in countries.py
>
> from gluon.html import *
> COUNTRIES=['United States', 'Afghanistan', ...]
> def countries_widget(field, value):
> return SELECT(COUNTRIES, _id=0)
>
> and I get this error:
> File "/home/darksun4/Sources/web2py/gluon/sqlhtml.py", line 595, in
> __init__
> inp = field.widget(field, default)
> File "/home/darksun4/Sources/web2py/applications/myapp/modules/
> countries.py", line 4, in countries_widget
> AttributeError: 'list' object has no attribute 'options'
>
> If I place my widget code in db.py, everything works ok.
>
> Also, what do you think about a db field, countries? Should I commit
> something like that?
>
> On Oct 7, 2:44 pm, Jon Romero <[email protected]> wrote:
>
>
>
> > I have created a module (inside my application/modules) and I use
> > SELECT.
> > I tried importing gluon.tools but no go. All I get is this error:
>
> > NameError: global name 'SELECT' is not defined
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---