wagtail / wagtail

A Django content management system focused on flexibility and user experience

Home Page:https://wagtail.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

custom workflow model

arshyia3000 opened this issue · comments

Is your proposal related to a problem?

yes, need to add some fields to Workflow model

Describe the solution you'd like

suggest to make Workflow model be able to customized, same as Document as Image

Describe alternatives you've considered

i can add a field to Workflow model myself, but in the future that customized Workflow model is provided, I would need to migrate

Additional context

Is there anything else you can add about the proposal?

No.

Working on this

Workflow model needs to be abstracted from AbstractWorkflow. def get_workflow_model(): needs to be defined, same as Document and image models.

Anyone can contribute to this. View our contributing guidelines, add a comment to the issue once you’re ready to start.

Hi @arshyia3000 - thanks for the suggestion. Can you give a specific example of where this might be useful?

We do already have the ability to subclass the Task model - would this achieve what you want?

Also I did a blog post on adding fields, it should be possible to add a field (relation to another model) without needing to modify the underling task model.

https://dev.to/lb/adding-tasks-with-a-checklist-to-wagtail-workflows-29b8

Thank you, guys, for the quick reply and suggestions.

Yes, I'm aware of the ability to customize the Task model, but having the ability to customize the Workflow model would provide further capabilities.

Before explaining the reasons, I suggest reading this valuable text about scalability issues in Django projects by DoorDash folks: Scalability Tips by DoorDash

Reasons:
In our admin panel, we have different users with different profiles. Having the ability to make a customizable Workflow model would allow us to provide a viewset that can create workflows for themselves and view their own workflows.

Currently, this can be done in the Task model. By customizing and adding a profile field to the Task model, it can be handled for task-related objects, but not for workflow objects.

The Task, Image, and Document models are subclassed from Abstract models, making customization straightforward. However, the Workflow model does not inherit from an AbstractWorkflow model. I suggest that, even if making the Workflow model customizable is not a priority now, it would be a good idea for the first step to have it inherited from an abstract model. For example:

#/home/content/venv/lib64/python3.10/site-packages/wagtail/models/__init__.py
class Workflow(ClusterableModel):
    name = models.CharField(max_length=255, verbose_name=_("name"))
    active = models.BooleanField(
        verbose_name=_("active"),
        default=True,
        help_text=_(
            "Active workflows can be added to pages/snippets. Deactivating a workflow does not remove it from existing pages/snippets."
        ),
    )

class A

class AbstractWorkflow(ClusterableModel):
    name = models.CharField(max_length=255, verbose_name=_("name"))
    active = models.BooleanField(
        verbose_name=_("active"),
        default=True,
        help_text=_(
            "Active workflows can be added to pages/snippets. Deactivating a workflow does not remove it from existing pages/snippets."
        ),
    )
    class Meta:
        abstract = True



class Workflow(AbstractWorkflow):
   pass

I should add that my purpose can be achieved by showing the queryset of the workflow objects that is created by user, or their related profile. but having an abstract workflow model would give other capabilities to work around as well and customize workflow model more.

also, this can be achieved by injecting new filed to Workflow model, per this similar question:
https://stackoverflow.com/questions/2181039/how-do-i-extend-the-django-group-model

if not hasattr(Workflow, 'extra_field'):
    field = models.CharField(max_length=180, null=True, blank=True)
    field.contribute_to_class(Workflow, 'extra_field')

Though, i think making Workflow abstracted would be beneficial. I'll try to make PR this week.

@arshyia3000 - #11584 has been raised that may make some kinds of customisations like this easier.

Once merged we will close this issue as you should have a bit more capability once that gets released.

We may not officially support a full set of custom workflows though, so if you feel that this should be a documented approach with more capabilities maybe we can re-open this issue.

There's also the potential avenue for proxy models which are being explored in other areas like Pages. See #4973 & other related items.