django-fsm
django-fsm copied to clipboard
Implement Transition.__hash__ and __eq__ for 'in' operator
Hello Folks,
For managing te state of your models in a Django project this library is a perfect fit. So thanks for providing this excellent library.
I find myself looping a lot over the results of get_available_FIELD_transitions
to check if an transition is available.
Therefore I decided to make the Transition
object hashable by implementing the __hash__
and __eq__
methods.
This adds support for a clean way of checking if a transition is available in a certain context
if 'publish' in blog.get_available_state_transitions():
do_logic()
Looking forward to receive your feedback.
each transition belong to a FSMMeta
instance.
I would be great to make sure that we don't conflate different transitions that share the name but are attached to different state machines.
Hi @ticosax, thanks for your feedback. We can extend the __eq__
~~method to incorporate the FSMMeta~~, although i'm not familiar with the situations wherein transitions have the same name (a class method is unique right?).
How can I create an use case that matches what you are describing so I can add a test case for it?
You are right, name is not overridable (unlike I assumed it was a parameter). then, there couldn't be name collision My bad, thanks.
@property
def name(self):
return self.method.__name__
@kmmbvnr thanks!