I'm using django-fsm to implement a state machine. The code looks like
def user_ok_to_check_me( instance, user):
...
class Job( models.Model):
# ... many screenfulls of code
@transition( field=state, target=BOOKING, source=CHECKING, permission=user_ok_to_check_me)
def fail_checking(self, **kwargs):
...
and it's working. Code readability is impaired by having that little utility function outside the class it belongs with, so I tried
class Job( models.Model):
# ... many screenfulls of code
@staticmethod
def user_ok_to_check_me( instance, user):
...
@transition( field=state, target=BOOKING, source=CHECKING, permission=user_ok_to_check_me)
def fail_checking(self, **kwargs):
which does not work. Not sure what user_ok_to_check_me
does now do, it behaves like a no-op function always returning True even when all it does is return False
Why? And is there any way to declare this little function inside the class? (It's just a little bit too long to use lambda instance, user:
)