Skip to main content

A Django app to run management commands from the admin panel

Project description

django-admin-commander

A Django app to run management commands from the admin panel with action logging and permission control.

Installation

pip install django-admin-commander

Usage

Add "django_admin_commander" to the end of INSTALLED_APPS in your project's settings.py:

INSTALLED_APPS = [
    ...,
    "django_admin_commander",
]

Run python manage.py migrate to register the dummy command model.

Next, add a setting named ADMIN_COMMANDS to your project's settings.py. This setting should be a dictionary where:

  • Keys are strings representing the app names.
  • Values are either the string "__all__" to enable all commands for the app, or an iterable of strings specifying which commands to show.

To enable general Django commands, use the app name "django.core". For example:

ADMIN_COMMANDS = {
    "django.contrib.staticfiles": "__all__",
    "django.core": ["check", "diffsettings"],
    "django.contrib.sessions": "__all__",
}

That's it! Now, when you access the admin panel with the custom permission enabled explicitly or as a superuser, you'll see a section for running management commands. Commands you've executed will also appear in your recent actions panel:

admin panel view

Clicking View or Run Management Commands opens a view where you can choose and execute the enabled commands.

run command view command groups

Once selected, the command usage info is automatically displayed below the Run Command button:

usage info

You can pass any command arguments in the Arguments field.

If the command expects user input, it can be provided in the User Input field and will be passed to the command when prompted.

[!NOTE] If you don't want to allow input to be passed to the command prompt, you can disable the User Input field entirely by setting ADMIN_COMMANDS_ALLOW_USER_INPUT to False in your project's settings.py.

After execution, the result is displayed as a message at the top of the screen:

command output

[!CAUTION] Some commands are not suited to be run this way and may cause the response process to hang. For example, the django.core command test. It's your responsibility to enable only the commands you actually want to run from the admin panel.

Clicking the History button (with the appropriate permission or as a superuser) lets you view all log entries for executed commands:

history

Permissions

In addition to standard admin view checks, django-admin-commander verifies whether the user has the custom run_management_command permission before allowing access to the run command view or executing commands:

permission

If the user is not a superuser, this permission must be explicitly granted.

To access the History view, the user must be a superuser or have the default Django "admin.view_logentry" permission.

Settings

List of available settings:

ADMIN_COMMANDS

A dictionary where keys are app names and values are either `'__all__'` to show all commands for the app or an iterable of command names to show. Default is an empty dictionary.

ADMIN_COMMANDS_ALLOW_USER_INPUT

Set to `True` to allow user input to be passed to the command's stdin when prompted. Set to `False` to disable the field. Default is `True`.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_admin_commander-0.4.0.tar.gz (370.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_admin_commander-0.4.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file django_admin_commander-0.4.0.tar.gz.

File metadata

  • Download URL: django_admin_commander-0.4.0.tar.gz
  • Upload date:
  • Size: 370.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_admin_commander-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a72dd03bfa8993efb94bbd553d2d3e88a380850c6cfcb1d65f7ceb6dd2eb2020
MD5 173ff39369355cdb6992217e58ed38a5
BLAKE2b-256 0dd65285b9bcfe7ef8ca63f3065392dbd1311a23968b021e830772cfcded450b

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_admin_commander-0.4.0.tar.gz:

Publisher: python-publish.yml on Lcrs123/django-admin-commander

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_admin_commander-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin_commander-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b634aca9cb4ff79e2d048365eab45517416754000ec40ee857aa79282c154c4
MD5 93a6affb6b0f1914201867b22aae0ee8
BLAKE2b-256 f5d8cf7b09f058ee0cf9da9646253ec7e6e5d1d505d69ec3966e5a717e89da5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_admin_commander-0.4.0-py3-none-any.whl:

Publisher: python-publish.yml on Lcrs123/django-admin-commander

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page