[Answer]-How to define instance methods from wrap

1👍

Move the self to wrap()‘s definition:

def wrap_has_perm(perm):
    def wrap(self):

However, a more Pythonic way to do this might be to use functools.partial:

from functools import partial

class Auth(models.Model):
    def has_perm(self, perm):
        # ...

    can_add_order = partial(has_perm, perm='finance.normal')

    can_review_order = partial(has_perm, perm='finance.review')

    is_leader = partial(has_perm, perm='finance.leader')

    is_finance = partial(has_perm, perm='finance.finance')
👤Amber

Leave a comment