Commits

Ian George committed 8e4aa4a

Added some South introspection rules so I can migrate models with state.

Comments (0)

Files changed (2)

statemachine/fields.py

         foo.blah.change('new_state')
         foo.save()
     """
-
     __metaclass__ = models.SubfieldBase
     description = "Finite State Machine Field"
+    machine = None
 
     def __init__(self, machine, default_choices_all=False, *args, **kwargs):
         """
 
         return state_choices
 
+try:
+    import south
+    south_available = True
+except ImportError:
+    south_available = False
+
+if south_available:
+    from south.modelsinspector import add_introspection_rules
+    default_machine = FSM()
+    add_introspection_rules([
+        (
+            [FSM_StateField], # Class(es) these apply to
+            [],         # Positional arguments (not used)
+            {           # Keyword argument
+                "machine": ["machine", {"default": default_machine}],
+                },
+            ),
+        ], ["^statemachine\.fields\.FSM_StateField"])

statemachine/fsm.py

 
     def __init__(self, verify_on_execute=True):
         self.states = deepcopy(self.base_states)
-        self.__state = self.states.keys()[0]
+        try:
+            self.__state = self.states.keys()[0]
+        except IndexError:
+            self.__state = ''
         self.dbg = None
         self.verify_on_execute = verify_on_execute