Issue
I am using django_fsm to manage state in my model. My model looks like:
from django.db import models,
from django_fsm import FSMField, transition
class MyModel(models.Model):
STATES = (
('pending', _('Pending')),
('active', _('Active'))
)
state = FSMField(choices=STATES, default='pending', protected=True)
@transition(field=state, source='pending', target='active')
def change_state(self):
pass
Should I add self.save() to change_state? Will it be called?
Solution
If calling change_state()
succeeds without raising an exception, the state field will be changed, but not written to the database.
So for making changes into database you need to call obj.save() explicitly
def change_view(request, model_id):
obj = get_object__or_404(MyModel, pk=model_id)
obj.change_state()
obj.save()
return redirect('/')
Answered By - Satendra
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.