Skip to main content

Expose Django management commands in the admin

Project description

pypi

django-managerie

:lightbulb: Expose Django management commands as forms in the admin

Requirements

  • Django 3.2+ (this project tracks Django's end-of-life policy)
  • Python 3.7+

Installation

Install the package as you would any Python package, then add django_managerie to your INSTALLED_APPS.

Automatic patching

This is the easiest way to get up and running. You can have Managerie patch the admin site's dashboard view to include pseudo-models with the name "Commands" for all apps where management commands are available, and while it's at it, it'll also include URLs of its own.

Hook up Managerie to your admin site (e.g. in urls.py, where you have admin.autodiscover()), like so:

from django.contrib import admin
from django_managerie import Managerie
# ...
managerie = Managerie(admin_site=admin.site)
managerie.patch()

No patching

This is likely safer (in the presence of slightly less tolerant 3rd party apps that mangle the admin, for instance), but you can't enjoy the luxury of the Commands buttons in the admin dashboard.

from django.contrib import admin
from django.conf.urls import include, url
from django_managerie import Managerie
# ...
managerie = Managerie(admin_site=admin.site)
# ...
urlpatterns = [
    # ...
    # ... url(r'^admin/', include(admin.site.urls)), ...
    url(r'^admin/', include(managerie.urls)),  # Add this!
]

Usage

If you allowed Managerie to patch your admin, superusers can now see Commands "objects" in the admin dashboard. If you didn't patch the admin, you can access a list of all commands through /admin/managerie/ (or wherever your admin is mounted).

If you click through to a command, you'll see the arguments of the command laid out as a form. Fill the form, then hit "Execute Command", and you're done! :sparkles:

Accessing the Django request from a managerie'd command

Managerie sets _managerie_request on the command instance to the current Django request. You can use it to access the request, for instance, to get the current user.

TODO

  • More argparse action support
  • Multiple-argument support (nargs)

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_managerie-0.5.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

django_managerie-0.5.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file django_managerie-0.5.1.tar.gz.

File metadata

  • Download URL: django_managerie-0.5.1.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.0

File hashes

Hashes for django_managerie-0.5.1.tar.gz
Algorithm Hash digest
SHA256 a68bca3eb87089ec3d42684b80250585f86ee0eaa9368105f0c0ba0b2ea9ed3d
MD5 a981d5e9a5776a212ee033d7a5c62974
BLAKE2b-256 b0d19dca6a07a72221ceac0bf75ea26611692b38cacccf853827a27923261194

See more details on using hashes here.

File details

Details for the file django_managerie-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_managerie-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 64ebbf9312f8a8af20eab1ce148cae3f8f9e626b60de8a43b7ed4a64a242e2b9
MD5 557020cb8d776f4e6fbd157c8736e109
BLAKE2b-256 05877fd2efc9ad3bd8ea7c3aae6a30f54edf73880e5f38cc15597ab1a73d8520

See more details on using hashes here.

Supported by

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