Nice. :-)

On Sat, May 4, 2013 at 12:16 AM, Massimo Di Pierro
<massimo.dipie...@gmail.com> wrote:
> This is in trunk but instead of
>
> db.define_table('person',
>     Field('name'),
>     Field('gender'),
>     Field('birthdate', 'date'))
>
> db.define_table('animal',
>     Field('name'),
>     Field('gender'),
>     Field('birthdate', 'date'))
>
>
> # Bind the function to tables.
> # Note the use of "self".
> # Due to this decorator, we're "inside" the instance.
>
> @make_member_of(db.person, 'just_men')
> @make_member_of(db.animal, 'just_males')
> def get_just_gender_equals_m(self):
>     return self._db(self.gender == 'm').select()
>
>
> # Use the function as a regular table method.
> db.person.just_men()
> db.animal.just_males()
>
> You instead do:
>
> @db.person.add_method.just_men
> @db.animal.add_method.just_males
> def get_just_gender_equals_m(self):
>     return self._db(self.gender == 'm').select()
>
> db.person.just_men()
> db.animal.just_males()
>
>
> I really love this!
>
> On Friday, 3 May 2013 09:27:29 UTC-5, viniciusban wrote:
>>
>> To make generic query functions truly generic, now you can stack or
>> chain @make_member_of decorator.
>>
>> It's now a slice:
>>
>> http://www.web2pyslices.com/slice/show/1625/turn-a-function-into-a-table-method
>
> --
>
> ---
> 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/groups/opt_out.
>
>

-- 

--- 
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/groups/opt_out.


Reply via email to