我分割了流程,并将几个任务分配给不同的用户。我如何才能:
发布于 2020-06-22 11:49:08
验证流应该在视图中结束的日期时间。
至少有一次,您必须访问一些视图,以验证流是否已经结束。在那里,您可以实现views.py bellow中提供的片段。
在您的模型中使用@property标记,除其他外,您可以动态执行一些验证,并在请求时将其返回,就像模型属性一样。
参考资料:https://docs.djangoproject.com/en/3.0/glossary/#term-property
示例:https://docs.djangoproject.com/en/3.0/topics/db/models/#model-methods
models.py
from django.db import models
from django.utils import timezone
class Flow(models.Model):
ends = models.DateTimeField
@property
def is_active(self):
return timezone.now() < self.endsviews.py
from django.http import HttpResponse
def interact_with_flow(request, pk)
if Flow.is_active:
status = 'Flow Active'
else:
status = 'Flow Ended'
return HttpResponse(request, status)https://stackoverflow.com/questions/62513144
复制相似问题