Is it possible to create a custom admin action for the django admin that doesn't require selecting some objects to run it on?



For #1, you don’t do this sort of thing in the admin. If you want a process to run on a scheduled basis, the easiest way is to create a custom management command and schedule it either through Celery Beat or cron.

For #2, again, this isn’t something to do in the admin. From Admin actions | Django documentation | Django

The basic workflow of Django’s admin is, in a nutshell, “select an object, then change it.”


In these cases, Django’s admin lets you write and register “actions” – functions that get called with a list of objects selected on the change list page.

I’d create a separate view for this, or possibly a custom command depending upon whether this is related to your first question.

— Using Google translate:

对于 #1,您不会在管理员中执行此类操作。 如果您希望进程按计划运行,最简单的方法是创建自定义管理命令并通过 Celery Beat 或 cron 计划它。

同样,对于 #2,这不是在管理员中要做的事情。 来自 Admin actions | Django documentation | Django

Django 管理的基本工作流程简而言之就是“选择一个对象,然后更改它”。

在这些情况下,Django 的管理员允许您编写和注册“操作”——使用在更改列表页面上选择的对象列表调用的函数。