Skip to content
This repository was archived by the owner on Jul 3, 2019. It is now read-only.

Conversation

@fladi
Copy link
Contributor

@fladi fladi commented Jan 20, 2016

django-fsm provides a method called get_all_state_transitions to get a list of
all available transitions.

django-fsm provides a method called `get_all_state_transitions` to get a list of
all available transitions.
@jacobh
Copy link
Owner

jacobh commented Jan 22, 2016

which versions of django-fsm did get_all_status_transitions work with and which work with get_all_state_transitions?

@fladi
Copy link
Contributor Author

fladi commented Jan 22, 2016

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.

@jacobh
Copy link
Owner

jacobh commented Jan 25, 2016

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.

@alexdutton
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants