If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

Note: this recipe makes web2py has the same nicety of Django managers. If you haven't heard about managers in models, see Model Managers slide and the Managers official documentation.

 

Web2py doesn't force us to define models as classes. It's a pragmatic approach, but lead us to some lack of organization. So, it's common to see functions in models directory concerning common table access, i.e. queries commonly used in your project. The solution would turn these functions into table methods.

 

It's what we'll show now.

The secret is  the @make_member_of decorator:

So, just define the make_member_of() function before your table definitions and enjoy your new table methods.

Related slices

Comments (0)


Hosting graciously provided by:
Python Anywhere