Reputation: 575
I have created a product snippet as suggested here to ensure they go to a workflow. This is because I do not want products they create or update to automatically appear to the public. I would like to approve them first.
However when I pragmatically update the snippet and do
instance.save()
It doesn't go to my workflow.
If i try save a revision it also still doesn't go to my workflow.
instance.save_revision()
What is the correct way so that when my user creates or updates their products they go to my workflow?
Upvotes: 0
Views: 39
Reputation: 575
@gasman provided an answer that worked for the most part but you have to add the following before, in the event you are creating a new snippet.
instance.save_revision()
workflow = instance.get_workflow()
workflow.start(instance, user)
This is because you will get an error that your revision_id is null and violates a constraint.
According to the documentation, the RevisionMixin and DraftMixin are perquisites for WorkflowMixin.
If anyone who supports Wagtail is reading, there is a lot in the way of improving your documentation that could be done.
Upvotes: 0
Reputation: 25227
Following the logic from the code that handles submitting to a workflow within the admin interface, a newly-created instance that is not already in a workflow can be submitted to a workflow as follows:
workflow = instance.get_workflow()
workflow.start(instance, user)
Upvotes: 0