Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 1.11, example with global states machine initialization fails #38

Open
AlexPython opened this issue Apr 15, 2018 · 0 comments
Open

Comments

@AlexPython
Copy link

Hi!

I tried the example described in the manual to have a global states machine for a Django class.
Copy-pasting the exact sample fails in Django 1.11 with: TypeError: __init()__ takes 1 positional argument but 30 were given

Below is my code:

def after_transition(e):
    # to test callbacks
    print("AFTER transition")


def printstatechange(e):
    # to test callbacks
    print('event: %s, src: %s, dst: %s' % (e.event, e.src, e.dst))


def welcome_back(e):
    # to test callbacks
    print("welcome back!")


class Order(PaidModel, FysomGlobalMixin, models.Model):

    GSM = FysomGlobal(
        events=[('open', 'complete', 'reset'),
                {
                    'name': 'open',
                    'src': 'draft',
                    'dst': 'open',
                },
                {'name': 'complete', 'src': '*', 'dst': 'completed'},
                {'name': 'reset', 'src': '*', 'dst': 'draft'},
                ],
        initial='draft',
        final='completed',
        state_field='status',
        callbacks={
            'onopen': after_transition,
            'onchangestate': printstatechange,
            'onreenteropen': welcome_back,
        }
    )

    def __init__(self):
        self.status = None
        super(Order, self).__init__()

    status = models.CharField(
        _('state'),
        max_length=30,
        blank=True, null=True,
    )
	
	# other fields
	
    def __str__(self):
        return str(self.id) # modified for this short example

Fails as soon as I access any instance of Order model.

What am I doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant