Skip to content

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

@AlexPython

Description

@AlexPython

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions