GithubHelp home page GithubHelp logo

ibrahim12 / django-admin-row-actions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from djangoadminhackers/django-admin-row-actions

0.0 1.0 0.0 31 KB

Add a drop-down 'actions' menu to each row of your Django model's admin changelist

License: Other

Python 63.50% JavaScript 31.60% HTML 4.90%

django-admin-row-actions's Introduction

Django Admin Row Actions

Allows you to easily define a drop-down 'actions' menu that is appended as the final column in your model's changelist and perform actions on that row.

Menu items can call urls or methods, can be disabled, have tooltips, etc.

I've extracted this from code written for http://hireablehq.com/. The admin there has Bootstrap available but I've modified this version to use a standalone jQuery dropdown.

Installation

  1. Install from PyPI:

    pip install django-admin-row-actions

    or install using pip and git:

    pip install git+https://github.com/DjangoAdminHackers/django-admin-row-actions.git
  2. Add to INSTALLED_APPS:

    INSTALLED_APPS = [
        ...
        'django_admin_row_actions',
        ...
    ]
  3. Add the mixin to your ModelAdmin:

    from django_admin_row_actions import AdminRowActionsMixin
    ...
    
    class ExampleAdmin(AdminRowActionsMixin, admin.ModelAdmin):
        ...
  4. Define a get_row_actions method on your ModelAdmin

    def get_row_actions(self, obj):
        row_actions = [
            {
                'label': 'Edit',
                'url': obj.get_edit_url(),
                'enabled': obj.status is not 'cancelled',
            }, {
                'label': 'Download PDF',
                'url': obj.get_pdf_url(),
            }, {
                'label': 'Convert',
                'url': reverse('convert_stuff', args=[obj.id]),
                'tooltip': 'Convert stuff',
            }, {
                'label': 'Cancel',
                'action': 'mark_cancelled',
            },
        ]
        row_actions += super(ExampleAdmin, self).get_row_actions(obj)
        return row_actions

The first three menu items are simple links to a url you provide by whatever means you choose.

The final one defines 'action' instead of 'url'. This should be the name of a callable on your ModelAdmin or Model class (similar to ModelAdmin.list_display).

You can add mouseover tooltips to each individual actions with the 'tooltip' dictionary key, and enable/disable individual actions for each individual object with the 'enabled'.

Credits

Inspired (and code based on): django-object-actions

Includes parts of jquery-dropdown; credits go to Cory LaViska.

django-admin-row-actions's People

Contributors

andybak avatar blag avatar midvik avatar phpdude avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.