django - 自动删除超过 30 天的博文
问题描述
我想在我的 Django 项目中自动删除超过 30 天的博客文章。我不知道该怎么做。
解决方案
这很简单。
创建一个管理命令,每月使用 crontab 调用它。
crontab - https://tecadmin.net/crontab-in-linux-with-20-examples-of-cron-schedule/
管理命令 Django - https://simpleisbetterthancomplex.com/tutorial/2018/08/27/how-to-create-custom-django-management-commands.html
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Delete blog post'
def handle(self, *args, **kwargs):
# Do stuff here - Delete posts
crontab
0 0 * * * python /path/to/manage.py mycommand
推荐阅读
- cookies - _abck 和 bm_sz 的用途是什么?
- flutter - 异步函数不等待
- google-analytics - 行为部分中的 Google 分析事件未显示
- css - 渐变动画使 CSS 无法在 Internet Explorer/Edge/Safari 上正确显示
- z3 - 变量是否有最大值大小?
- java - 在 RecyclerView 中显示多个数据时出现 java.lang.IndexOutOfBoundsException
- java - 检索 Apache circularfifobuffer 中最后一项的计算效率最高的方法是什么?
- r - ggplot2 堆积条形图,每个 X 变量 2 个条形图
- scala - Spark 会话目录失败
- heroku - Heroku 网站可以读取 Server Side Includes