Skip to main content

Django mixin to easily add buttons to any ModelAdmin

Project description

django-admin-extra-buttons

Pypi coverage Test ReadTheDocs

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.

Will be possible to create wizards, actions and/or link to external resources as well as api only views.

It provides 3 decorators:

  • button() to mark a method as extra view and show related button
  • link() 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, link, view

class MyModelModelAdmin(extras.ExtraButtonsMixin, admin.ModelAdmin):

    @link(label='Search On Google', change_form=True, change_list=False)
    def search_on_google(self, button):
        obj = button.context['original']
        button.href = f'http://www.google.com?q={obj.name}'

    @button() # /admin/myapp/mymodel/update_all/
    def consolidate(self, request):
        ...
        ...

    @button() # /admin/myapp/mymodel/update/10/
    def update(self, request, pk):
        # if we use `pk` in the args, the button will be in change_form
        obj = self.get_object(request, pk)
        ...

    @button(permission=lambda request, obj: request.user.is_superuser)
    def empty_table(self, request):
        if request.method == 'POST':
            self.model.objects.all().delete()
        else:
            return extras._confirm_action(self, request, self.truncate,
                                   'Continuing will erase the entire content of the table.',
                                   'Successfully executed', )

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-extra-buttons-0.1.0.tar.gz (5.7 MB view details)

Uploaded Source

File details

Details for the file django-admin-extra-buttons-0.1.0.tar.gz.

File metadata

  • Download URL: django-admin-extra-buttons-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 importlib_metadata/4.3.0 pkginfo/1.5.0.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.8

File hashes

Hashes for django-admin-extra-buttons-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bec7d3d24ec9d3553af8eee74cd511f8a0c436ec9b37bf3d38683067b2a4709c
MD5 0c61839918fcebc0bd0831ffc3b4a60b
BLAKE2b-256 aa90ac3961ef17ced95cc6ab3ef21856721cf8d8790590f02978dd8a63dec834

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