Skip to content

Having a StateLog on object creation with the default state? #145

@ddahan

Description

@ddahan

In my app, I'm trying to show the full life cycles of objects using FSM.
While I love django-fsm-log for that purpose, the object creation itself is missing from these logs, as it's not a transition.
But after all, we could see this first step as a transition from the "None state" to the "created (default) state".

That's why I was wondering what is the best way, to create a StateLog instance when my object is created with the default state.

For example:

class SomeObject(models.Model):

    state = FSMField(
        choices=SomeObjectState.choices,
        default="created",
        protected=True,
    )


some_obj = SomeObject.objects.create()
StateLog.objects.for_(some_obj).count() # I would love to have 1 item here!

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions