Allow calling registered custom functions (system tools, script functions, etc.) via admin UI or manage.py command.
The inspiration for this library comes from https://github.com/timonweb/django-clearcache.
Install the package via pip:
pip install django-adminutilities
Add adminutilities to your INSTALLED_APPS setting, make sure it's above django.contrib.admin like this:
INSTALLED_APPS = [ 'adminutilities', 'django.contrib.admin', ]
Add adminutilities.middleware.GetAllAdminToolFunctionsMiddleware to your MIDDLEWARE setting like this:
MIDDLEWARE = [ ... 'adminutilities.middleware.GetAllAdminToolFunctionsMiddleware', ]
Add adminutilities to your urls.py:
urlpatterns = [ ... path('admin/', admin.site.urls), path('admin/adminutilities/', include('adminutilities.urls')), ]
Create a new file admin_tools.py in your app folder, and define your custom functions, for example:
from adminutilities.decorators import admin_tool @admin_tool def my_custom_function(): return 'Hello, world!'
Go to /admin/adminutilities/ and you will see the registered functions. If you click the function, it will execute the function and show the result.
You can also call the function via manage.py command, need to provide the full path of the function (app_name.function_name), for example:
python manage.py adminutilities main.my_custom_function
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.