nab*_*eel 7 django recurrence notifications date django-timezone
我想每天午夜运行这个功能来检查expiry_date_notification.我能做什么?我是django和python的新手.
def check_expiry_date(request):
products = Product.objects.all()
for product in products:
product_id = product.id
expiry_date = product.expiry_date
notification_days = product.notification_days
check_date = int((expiry_date - datetime.datetime.today()).days)
if notification_days <= check_date:
notification = Notification(product_id=product_id)
notification.save()
Run Code Online (Sandbox Code Playgroud)
Jos*_*osh 11
正如其他人所说,Celery可以安排任务在特定时间执行.
from celery.schedules import crontab
from celery.task import periodic_task
@periodic_task(run_every=crontab(hour=7, minute=30, day_of_week="mon"))
def every_monday_morning():
print("This is run every Monday morning at 7:30")
Run Code Online (Sandbox Code Playgroud)
通过安装 pip install django-celery
| 归档时间: |
|
| 查看次数: |
5961 次 |
| 最近记录: |