Commits

Ian George committed 580afbd

History saving correctly and tested

Comments (0)

Files changed (2)

statemachine/models.py

 
     # log of to / from, state info, date, user
     from_state = models.CharField(max_length=25)
-    input = models.CharField(max_length=20, null=True, blank=True)
     to_state = models.CharField(max_length=25)
     change_date = models.DateTimeField(auto_now=True)
     user = models.ForeignKey(User, null=True, blank=True)
     Abstract base class for a model requiring a state machine field
     """
     state = models.CharField(max_length=25, default="start")    
-    state_history = generic.GenericRelation(StateMachineHistory)
+    state_history = generic.GenericRelation(StateMachineHistory, content_type_field='machine_type', object_id_field='machine_id')
     _current_state = ''
 
     def __init__(self, *args, **kwargs):
         
     def transition(self, transition_to, user, notes='', save_model=True):
         #transition this model
-
+        from_state = self.state
         self.state = self.__machine__.execute(transition_to, self)
 
         # we can allow save as a separate operation
         if STATE_MACHINE_KEEP_HISTORY:
             s = StateMachineHistory()
             s.machine = self
-            s.from_state = self._current_state #should get this from the transition mechanism
+            s.from_state = from_state
             s.to_state = self.state
             s.user = user
             s.notes = notes

statemachine/tests.py

         self.fsm.transition("step2", None)
         self.fsm.transition("end", None)
 
-        #print len(fsm.state_history)
+        for item in self.fsm.state_history.all():
+            print "%s: %s - %s" % (item.change_date, item.from_state, item.to_state)