How to change/ insert the djnago finite state machines on fly from terminal window

204 Views Asked by At

I have below a.py djnago finite state machine program:

from django.db import models
from django_fsm import transition, 
                FSMIntegerField
from django_fsm import FSMField, transition
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
import django
django.setup()

from django.core.management import call_command
class Order(models.Model):
     STATUS_GO = 0
     STATUS_COME =1
     STATUS_CHOICES = (
      (STATUS_GO, 'GO'),
      (STATUS_COME,'come')
       )
product = models.CharField(max_length=200)
status = FSMIntegerField(choices=STATUS_CHOICES, default=STATUS_GO, protected=True)


   @transition(field=status, source=. 
  [STATUS_GO],  target=STATUS_COME)
   def walk(self):
       print("Target moved")

I would run above program as : Press F5.

  >>> State= order()

  >>> State.walk # input

   >>> Target moved # output

I would like understand by any chance, do djnago /python provide opportunities to insert STATES like ( STATUS_HOLD, STATUS_JUMP) from terminal window, in addition to already available.

So that these new states get positioned in programs. Any possibility. Thanks.

1

There are 1 best solutions below

0
T.D. Nathan On BEST ANSWER

Before:

  @transition(field=status, source=[STATUS_GO],  target=STATUS_COME)

Now:

 in=input("source")
 out =input("Target)
 @transition(field=status, source=in,  target=out)

Similarly for Status_choice, get inputs from user.

This helped me to have inputs on fly