开发者

Implementing workflows in Django Admin - Django

开发者 https://www.devze.com 2023-01-10 00:01 出处:网络
I have a nice admin 开发者_如何学运维panel setup so users can manage the data within the site.

I have a nice admin 开发者_如何学运维panel setup so users can manage the data within the site.

Problem is that I need to implement a workflow, so saved models can be approved from and to various stages, to then be finally published.


As the model in question is just one, I thougth of adding a boolean 'approved_for_publishing' field and a 'approved_by' manytomany field.

The obstancle is integrating this within the admin panel.

If someone has a few opinions on the topic that would be really awesome. =)


Some time early I completed similar functionality. Here is what you need to do: Create an approval status model, and have different variants of approval, i.e each model object represents different approval stage.Also you must have a StatusHistory model which reflects what current status does your article(for example) has.

class Article(models.Model)
      title=models.CharField(max_length=32)
      body=models.TextField()

class ApprovalStatus(models.Model):
      name=models.CharField(max_length=32)
      alias=models.CharField(max_length=32,pk=True)

class StatusHistory(models.Model):
      status=models.ForeignKey(ApprovalStatus)
      article=models.ForeignKey(Article)
      current=models.BooleanField(default=True)

So when in your admin you change the status of the article, a new StatusHistory object is created and old object is given current=False variable. This approach seems a bit bulky, but when you implement it, all you need easily falls into ORM: status history is just a list of all objects, changes to workflow involve only creating new approval status and changing your hardcoded status flow routines


django-werewolf is exactly what you're looking for (https://pypi.python.org/pypi/django-werewolf).

Check the example app here (https://bitbucket.org/barseghyanartur/django-werewolf/src).

For any questions and support, contact me.

0

精彩评论

暂无评论...
验证码 换一张
取 消