Django mixin to easily add buttons to any ModelAdmin
Project description
django-admin-extra-buttons
This is a full rewriting of the original django-admin-extra-url
. It
provides decorators to easily add custom buttons to Django Admin pages as well add views to any ModelAdmin
It allows to create wizards, actions and/or links to external resources as well as api only views.
It provides 3 decorators:
button()
to mark a method as extra view and show related buttonlink()
This is used for "external" link, where you don't need to invoke local views.view()
View only decorator, this adds a new url but do not render any button.
Install
pip install django-admin-extra-buttons
After installation add it to INSTALLED_APPS
INSTALLED_APPS = (
...
'admin_extra_buttons',
)
How to use it
from admin_extra_buttons.api import ExtraButtonsMixin, button, confirm_action, link, view
from django.http import HttpResponse, JsonResponse
from django.contrib import admin
class MyModelModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):
@button(permission='demo.add_demomodel1',
change_form=True,
html_attrs={'style': 'background-color:#88FF88;color:black'})
def refresh(self, request):
self.message_user(request, 'refresh called')
@button(html_attrs={'style': 'background-color:#DC6C6C;color:black'})
def confirm(self, request):
def _action(request):
pass
return confirm_action(self, request, _action, "Confirm action",
"Successfully executed", )
@link(href=None,
change_list=False,
html_attrs={'target': '_new', 'style': 'background-color:var(--button-bg)'})
def search_on_google(self, button):
original = button.context['original']
button.label = f"Search '{original.name}' on Google"
button.href = f"https://www.google.com/?q={original.name}"
@view()
def select2_autocomplete(self, request):
return JsonResponse({})
@view(http_basic_auth=True)
def api4(self, request):
return HttpResponse("Basic Authentication allowed")
Project Links
- Code: https://github.com/saxix/django-admin-extra-buttons
- Decumentation: https://saxix.github.io/django-admin-extra-buttons/
- Issue Tracker: https://github.com/saxix/django-admin-extra-buttons/issues
- Download Package: https://pypi-hypernode.com/project/django-admin-extra-buttons/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-admin-extra-buttons-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28c4fc2d9d15359d39ccf4be45cf5b25fb99713336c6e8c1fc0218baeb8344a3 |
|
MD5 | fb214123b870b6acbeb18c4f4213f41c |
|
BLAKE2b-256 | 5fd1dc29a896992647becd54b01a318b65cf251d8d2623d3e1c58891a8276886 |
Close
Hashes for django_admin_extra_buttons-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6428469b9a78d25fbcff80397c88d7372419e8c3a2c9fb4226ac432a3f3b9861 |
|
MD5 | 425cbdb55bc6720eb70007d92f3bac1f |
|
BLAKE2b-256 | 52bf8e86d8f8c99511052d5132587357f7765dbd10c2ed672ed20eaf27b54d62 |