In a model file: my_products = ['Type1', 'Type2', 'Type3']
Because (non-conditional) models are executed on every request before any controller or view, any objects defined in a model are available in any controller or view -- so in a controller or view, just refer to the my_products variable. You could of course also define the list in a module and import it wherever needed. Anthony On Sunday, November 26, 2017 at 10:05:21 AM UTC-5, Sarbjit wrote: > > Hello, > > I have defined a IS_IN_SET validator inside my models. Now, I want to use > the same list inside controllers and views. What is the best way to re-use > the same list inside controllers and views without having to duplicate the > code. Right now, I just copied the entire list inside my controller. So, if > I have to change anything, I have to change it at two places. > > db.define_table('products', > Field('type'), > auth.signature) > > db.products.type.requires = IS_IN_SET(['Type1', 'Type2', 'Type3']) > > An example snippet would be highly appreciated. > > Thanks ! > -- 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. For more options, visit https://groups.google.com/d/optout.