Django:如何跟踪线性(但灵活)的项目管理工作流程?

发布于 2024-09-15 03:37:09 字数 2383 浏览 5 评论 0原文

我正在 Django 中开发一个项目管理应用程序,它需要涉及不同用户组的线性响应过程(如 Django auth Groups 中)。响应过程中的每个步骤都有多个响应选项(大多数选项是该步骤所独有的),并被分配给特定组中的用户。该过程的下一步取决于用户的响应,有时可能需要向项目成员请求附加信息。

问题是我当前的实现看起来相当麻烦,我确信有更好的方法来跟踪响应过程。我希望有人能够提供一些关于更强大的解决方案的见解。

作为一个简单的示例,请考虑具有以下用户组的项目:销售代表、销售经理和项目经理。目前的模型如下所示:

class Project(models.Model):  
    assigned_to = models.ForeignKey(User, related_name="projects_assigned_to") #Indicates which user needs to respond next.  Will be sales_rep, sales_mgr, or project_mgr.
    sales_rep = models.ForeignKey(User, related_name="sales_rep_projects") #choices limited to "Sales Rep" Group  
    sales_mgr = models.ForeignKey(User, related_name="sales_mgr_projects") #choices limited to "Sales Manager" Group 
    project_mgr = models.ForeignKey(User, related_name="project_mgr_projects") #choices limited to "Project Manager" Group
    current_step = models.ForeignKey(Step, related_name="projects_with_current_step")
    previous_step = models.ForeignKey(Step, related_name="projects_with_previous_step")
    status = models.ForeignKey(Status) #Automatically assigned according to the user's response.  Includes things like "On Track", "On Hold", "Rejected", "Accepted", etc.

class Step(models.Model):
    name = models.CharField(max_length=50) 

class Status(models.Model):
    name = models.CharField(max_length=50) 

以下是该流程如何工作的简单概述:

  1. 销售代表创建一个新项目并将其分配给销售经理
  2. 销售经理会看到以下选项:
    (a) 批准项目或
    (b) 向销售代表索取更多信息
  3. 如果项目获得批准,则分配给项目经理,项目经理将面临以下选项:
    (a) 启动项目
    (b) 拒绝该项目
    (c) 向销售代表或销售经理请求更多信息
  4. 如果用户请求更多信息,项目将分配给该用户,他们只需提供文本框响应即可。但是,一旦收到他们的回复,项目就需要返回到上一步(这就是我跟踪上面的 current_step 和 previous_step 的原因)。在此示例中,如果项目经理向销售代表请求更多信息,则销售代表响应后,应将项目分配回项目经理,并使用与项目经理之前相同的响应选项(开始、拒绝、请求更多信息)。

完整的过程大约有 10 个左右的步骤。

让事情变得复杂的是,我还需要能够显示为每个步骤选择的响应。例如,如果销售经理批准了该项目,则应显示“销售经理批准了该项目”以及他们可能有的任何评论。该模型如下所示:

class Response(models.Model):
    comment = models.TextField()
    response_action = models.ForeignKey(ResponseAction)
    submitted = models.DateTimeField()

class ResponseAction(models.Model):
     """ I.e. 'Sales Manager approved the project', 'Project Manager commenced the project'"""  
     name = models.CharField(max_length=100)

现在每个响应操作的逻辑都硬编码在视图中,并且一个步骤与另一个步骤之间没有正式的关系。我觉得我应该使用更好的模型结构或数据结构来跟踪此工作流程,但我已经使用当前系统太久了,以至于我很难以不同的方式思考它。任何见解或灵感将不胜感激!如果我需要澄清任何事情,请告诉我。

I'm developing a project management application in Django that requires a somewhat linear response process involving different groups of users (as in Django auth Groups). Each step in the response process has several response options (most options unique to the step) and is assigned to a user within a particular group. The next step in the process is determined by the user's response, and occasionally additional information may need to be requested from one of the project's members.

The problem is that my current implementation seems rather cumbersome and I am certain there is a better way to keep track of the response process. I was hoping someone could provide some insight into a more robust solution.

As a simple example, consider a Project with the following user Groups: Sales Rep, Sales Manager, and Project Manager. The models currently looks like this:

class Project(models.Model):  
    assigned_to = models.ForeignKey(User, related_name="projects_assigned_to") #Indicates which user needs to respond next.  Will be sales_rep, sales_mgr, or project_mgr.
    sales_rep = models.ForeignKey(User, related_name="sales_rep_projects") #choices limited to "Sales Rep" Group  
    sales_mgr = models.ForeignKey(User, related_name="sales_mgr_projects") #choices limited to "Sales Manager" Group 
    project_mgr = models.ForeignKey(User, related_name="project_mgr_projects") #choices limited to "Project Manager" Group
    current_step = models.ForeignKey(Step, related_name="projects_with_current_step")
    previous_step = models.ForeignKey(Step, related_name="projects_with_previous_step")
    status = models.ForeignKey(Status) #Automatically assigned according to the user's response.  Includes things like "On Track", "On Hold", "Rejected", "Accepted", etc.

class Step(models.Model):
    name = models.CharField(max_length=50) 

class Status(models.Model):
    name = models.CharField(max_length=50) 

Here's a simple overview of how the process might work:

  1. Sales Rep creates a new project and it is assigned to Sales Manager
  2. Sales Manager is presented with the following options:
    (a) approve the project or
    (b) request more information from the Sales Rep
  3. If the project is approved, assign to Project Manager who is presented with the following options:
    (a) commence the project
    (b) reject the project
    (c) request more information from the Sales Rep or Sales Manager
  4. If more information is requested from a user, the project is assigned to that user and they just need to provide a textbox response. However, once their response has been received, the project needs to return to the previous step (this is why I keep track of current_step and previous_step above). In this example, if Project Manager requests more information from the Sales Rep, once the Sales Rep responds the project should be assigned back to the Project Manager with the same response options that he had before (commence, reject, request more information).

The full process has about 10 or so steps like these.

To complicate things, I also need to be able to display the response chosen for each step. For example, if the Sales Manager approves the project, it should display "Sales Manager approved the project" along with any comments they may have. The model looks like this:

class Response(models.Model):
    comment = models.TextField()
    response_action = models.ForeignKey(ResponseAction)
    submitted = models.DateTimeField()

class ResponseAction(models.Model):
     """ I.e. 'Sales Manager approved the project', 'Project Manager commenced the project'"""  
     name = models.CharField(max_length=100)

Right now the logic for each response action is hard coded in the view, and there's no formal relationship between one step and another. I feel like there's a better model structure or data structure I should be using to keep track of this workflow, but I've been working with the current system for so long that I'm having trouble thinking about it differently. Any insight or inspiration would be greatly appreciated! Let me know if I need to clarify anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国粹 2024-09-22 03:37:09

多利用 Step 模型。您可以让它将可能的后续步骤作为外键保存。这样您就可以通过更改数据来编辑流程(例如使用管理员,而不是对其进行硬编码)。也许是这样的:

class Step(models.Model):
    name = models.CharField(max_length=50)
    responsible_role = models.CharField(max_length=50) # this contains 'sales_rep', 'sales_mgr' etc
    allowed_actions = models.ManyToManyField('AllowedAction')

class AllowedAction(models.Model):
    name = models.CharField(max_length=50)
    next_step = models.ForeignKey('Step') # the next step, if this action is chosen

将实际项目历史记录分离到另一个模型:

class ProjectHistoryStep(models.Model):
    timestamp = models.DateTimeField()
    step = models.ForeignKey('Step')
    project = models.ForeignKey('Project')  

您可以使用此模型来跟踪项目的实际进度(不要忘记模型具有 get_next_by_FOO)。

您只需要 1 个视图来处理所有逻辑(它应该只调用 Project 类上的某些方法来完成实际工作) - 检查项目现在处于什么状态(该项目的最新 ProjectHistoryStep),以及用户的操作,并采取相应的行动。

Make more use of the Step model. You can have it hold the possible next steps as foreign keys. This way you can edit the flow by changing data (using the admin for example, instead of hardcoding it). Maybe something like:

class Step(models.Model):
    name = models.CharField(max_length=50)
    responsible_role = models.CharField(max_length=50) # this contains 'sales_rep', 'sales_mgr' etc
    allowed_actions = models.ManyToManyField('AllowedAction')

class AllowedAction(models.Model):
    name = models.CharField(max_length=50)
    next_step = models.ForeignKey('Step') # the next step, if this action is chosen

Seperate the actual project history to another model:

class ProjectHistoryStep(models.Model):
    timestamp = models.DateTimeField()
    step = models.ForeignKey('Step')
    project = models.ForeignKey('Project')  

You can use this model to track the actual progress of your projects (don't forget that models have get_next_by_FOO).

You'll only need 1 view that handles all the logic (it should just call some method on the Project class to do the actual work) - check what state the project is in now (latest ProjectHistoryStep for that project), and what was the User's action, and act accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文