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

**URL:** <https://forum.djangoproject.com/t/is-it-possible-to-create-a-custom-admin-action-for-the-django-admin-that-doesnt-require-selecting-some-objects-to-run-it-on/19273>\
**Category:** The Admin\
**Created:** [March 5, 2023, 9:06am UTC](https://forum.djangoproject.com/t/is-it-possible-to-create-a-custom-admin-action-for-the-django-admin-that-doesnt-require-selecting-some-objects-to-run-it-on/19273 "2023-03-05T09:06:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mrgorlay](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mrgorlay/32/11643_2.png) [@Mrgorlay](https://forum.djangoproject.com/u/Mrgorlay)\
**Post date:** [March 5, 2023, 9:06am UTC](https://forum.djangoproject.com/t/is-it-possible-to-create-a-custom-admin-action-for-the-django-admin-that-doesnt-require-selecting-some-objects-to-run-it-on/19273/1 "2023-03-05T09:06:57Z")

</div>

django-admin（4.1）中自定义了一个action，  
（1）问题一，怎么实现定时触发此action;（五分钟执行一次）

（2）问题二：在触发action时，怎么在自定义action中设置默认为全选，解除action限制默认的（请选中至少一个选项！）

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 5, 2023, 12:57pm UTC](https://forum.djangoproject.com/t/is-it-possible-to-create-a-custom-admin-action-for-the-django-admin-that-doesnt-require-selecting-some-objects-to-run-it-on/19273/2 "2023-03-05T12:57:31Z")

</div>

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](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/actions/)

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

and

> 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](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/actions/)

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

和

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

我会为此创建一个单独的视图，或者可能是一个自定义命令，具体取决于这是否与您的第一个问题相关。
