如何安排此程序的通知?我使用通道来创建通知,并使用"crontab“来调度,但是它不起作用。
def my_schedule_job():
vehicle_objs = Vehicle.objects.all()
for vehicle_obj in vehicle_objs:
insurance_expiry = vehicle_obj.insurance_expiry
insurance_expiry_date = insurance_expiry - timedelta(days=5)
today = date.today()
print('insurance_expiry_date',insurance_expiry_date)
print('today',today)
if insurance_expiry_date == today:
notification_obj = Notification(user_id=vehicle_obj.user_id,notification="Your insurance for {} will expire on {}".format(vehicle_obj.vehicle,insurance_expiry) ,is_seen=False)
notification_obj.save()
elif insurance_expiry_date <= today:
notification_obj = Notification(user_id=vehicle_obj.user_id,notification=vehicle_obj.vehicle + " insurance is going to expire on " + str(insurance_expiry),is_seen=False)
notification_obj.save()发布于 2022-03-07 16:26:01
您需要创建一个自定义manage.py命令来解决您的问题。为此,您需要创建一个<appname>/management/commands目录结构,并将代码放在该目录中的文件中,其中包含要运行的命令的名称的代码的文件名。例如,emails.py。
之后,Django希望在您的自定义管理命令中看到一些函数。您需要将代码放入相应的函数中。
回顾一下这个URL,如果你遇到问题,让我知道?
祝好运。
https://stackoverflow.com/questions/71382539
复制相似问题