drf-fsm-transitions
drf-fsm-transitions copied to clipboard
Fix method name to work with latest django-fsm API.
django-fsm provides a method called get_all_state_transitions
to get a list of
all available transitions.
which versions of django-fsm did get_all_status_transitions
work with and which work with get_all_state_transitions
?
I think my PR does not make much sense now that I looked at it in more detail. The name of the method depends on the name of the field where django-fsm stores its state. For my models this was state = FSMField()
. This gave my model instances a method named get_all_state_transitions
. You probably had status = FSMField()
on your model.
See django-fsm code for how this method is set on the model.
I'll see if I can come up with a better way to detect the name of the get_all_FIELD_transitions
method.
maybe we should change the code to something like:
from django_fsm import get_all_FIELD_transitions, FSMField
fsm_field = None
for field in instance._meta.get_fields():
if isinstance(field, FSMField):
fsm_field = field
break
transitions = get_all_FIELD_transitions(instance, fsm_field)
this should find the fsm field on a model instance, then pull out its transitions. note, I haven't tested that snippet. It will also blow up if you have more than 1 fsm field on a model.
Also I should probably add into the readme that this repo is a proof of concept and I didn't expect anyone to use it.
I'm playing with having two FSMFields on my model, so that wouldn't work for me. Maybe get_viewset_transition_action_mixin should take an additional argument that says which state field to use? Default to 'status' to maintain existing behaviour