Skip to main content

Django mixin to easily add urls to any ModelAdmin

Project description

pluggable django application that offers one single mixin class ExtraUrlMixin to easily add new url (and related buttons on the screen) to any ModelAdmin.

It provides two decorators link() and action().

  • link() is intended to be used for multiple records. It will produce a button in the change list view.
  • action() works on a single record. It will produce a button in the change form view.

Install

pip install admin-extra-urls

After installation add it to INSTALLED_APPS

INSTALLED_APPS = (
    ...
    'admin_extra_urls',
)

How to use it

from admin_extra_urls.extras import ExtraUrlMixin, link, action

class MyModelModelAdmin(ExtraUrlMixin, admin.ModelAdmin):

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


    @action() # /admin/myapp/mymodel/update/10/
    def update(self, request, pk):
        obj = self.get_object(pk=pk)
        ...

You don’t need to return a HttpResponse. The default behavior is:

  • with link() button is displayed in the ‘list’ view and the browser will be redirected to changelist_view
  • with action() button is displayed in the ‘update’ view and the browser will be redirected to change_view

Integration with other libraries

django-import-export

@admin.register(Rule)
class RuleAdmin(ExtraUrlMixin, ImportExportMixin, BaseModelAdmin):
    @link(label='Export')
    def _export(self, request):
        return self.export_action(request)

    @link(label='Import')
    def _import(self, request):
        return self.import_action(request)

Release history Release notifications

This version
History Node

1.9.0

History Node

1.8.0

History Node

1.7

History Node

1.6

History Node

1.5

History Node

1.4

History Node

1.3.1

History Node

1.3

History Node

1.2

History Node

1.1

History Node

1.0

History Node

0.8

History Node

0.7.1

History Node

0.7

History Node

0.6.1

History Node

0.5

History Node

0.4

History Node

0.3

History Node

0.2.1

History Node

0.1

History Node

0.1.dev20141008144353

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
admin-extra-urls-1.9.0.tar.gz (17.7 kB) Copy SHA256 hash SHA256 Source None Apr 18, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page