如何根据django中的结束日期自动删除记录 [英] How to automatically delete a record according to end date in django

查看:105
本文介绍了如何根据django中的结束日期自动删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下模型的django应用程序

I have a django app with the model below

Class Promotion(models.Model):
    name = models.CharField(max_length=256)
    start_date = models.DateTimeField()
    end_date = models.DateTimeField()

所以在创建促销记录时,我们将设置一个开始日期结束日期,所以当当前日期大于结束日期时,所有功能是什么记录应该自动从数据库中删除,否则会发送电子邮件....所以有些这种情况。

So during the creation of the promotion record, we will set a start date and end date to it, so what all the functionality is when the current date is greater than the end date, the record should be automatically deleted from the database, or else an email will be sent.... so some kind of these situations.

所以请允许我知道,如何处理这些情况,我的意思是当当前日期大于促销日期做某事.......

So can any one please let me know, how to handle these situations, i mean when the current date is greater than the promotion date do something.......

推荐答案

我将实施管理指令 end_date 的任何促销记录已过期。然后在Ubuntu(和Unix风味系统)中的计划任务 cron工作将会调用管理命令按照您通过 crontab 指定的时间表,在这种情况下,每天最少一次。

I would implement a management command that deletes any of the Promotion records that are "expired", i.e. their end_date has passed. Then a scheduled task, a cron job in Ubuntu (and Unix-flavoured systems), will call the management command at the schedule you specify via crontab, in this case least once daily.

这篇关于如何根据django中的结束日期自动删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆