【发布时间】:2021-10-03 18:58:07
【问题描述】:
信息:当我创建一个新客户时,我想将 pending_customer 设为 True,我将其设置为默认值 True,因此它工作正常,一个月后 pending_customer 自动设为 false。
我也尝试制作函数get_pending_customer 谁能做到我知道这不是我想做的方式。这就像一个基于任务的函数,它会在一个月后自动将 pending_customer 字段 True 变为 false。我想知道我该怎么做?
谁能告诉我最好的方法是什么?
models.py
from django.utils.timezone import datetime
class Customer(models.Model):
"""Customer Model"""
name = models.CharField(max_length=255)
phone = models.CharField(max_length=11)
created_on = models.DateTimeField(auto_now_add=True)
pending_customer = models.BooleanField(default=True)
"""Example""" # I know it's wrong way
def get_pending_customer(self):
today = datetime.date.today()
month = datetime.timedelta(30)
after_month = today + month
if after_month:
panding = self.object
panding.pending_payment = False
panding.save()
return today
【问题讨论】:
-
一个月后是否需要将pending_customer重置为True?还是完全依赖于 created_on 字段??
-
@umair 我只想让 pending_customer 在一个月后得到 False。忽略这个 created_on 这是今天的日期
-
请看看我的问题更新了!
-
似乎你需要一个调度器和一个额外的字段,其中包含它应该被打开的日期
-
是的,我需要调度器...
标签: django django-models django-rest-framework django-celery-beat