Skip to main content

Easy-to-use actions for Django admin inlines

https://img.shields.io/github/workflow/status/kvirt/django-inlines-actions/GH https://img.shields.io/codecov/c/github/kvirt/django-inlines-actions https://img.shields.io/pypi/v/django-inlines-actions

Installation

  1. Install django_inlines_actions

    pip install django_inlines_actions
  2. Add inlines_actions to your INSTALLED_APPS.

  3. Add the InlineActionsModelAdminMixin to your ModelAdmin.

  4. Add the InlineActionsMixin to your TabularInline.

  5. Add inline_actions attribute to your TabularInline as a tuple of your actions.

    inline_actions = ('your_action_name', 'another_action_name',)
  6. Every action must have following signature:

    def your_action_name(self, request, obj, parent_obj):

Usage

Action is basically a link to another url with corresponding view. It does not depends on form as some other solutions and not execute on Enter hit. Action should return None to return to the current changeform or a HttpResponse instance. If you want do disable Actions column set inline_actions to None.

inline_actions = ('change_title',)

def change_title(self, request, obj, parent_obj):
    obj.title  = obj.title + ' | ' + parent_obj.name
    obj.save()

Features

Permissions

Permissions are instance of list/tuple classes and can be either custom function or django built-in permission.

def your_action_name(self, request, obj, parent_obj):
    pass
your_action_name.permissions = ('permission_func_name', 'django_builtin_permission_name',)

permissions function must have following signature:

def permission_func_name(self, request, obj, parent_obj):

Must return False to fail permission check otherwise permission will be passed.

If permissions returns False action will no be rendered for user and action will raise PermissionDenied on execution.

Short Description

Short Description are either custom function or simple string.

def your_action_name(self, request, obj, parent_obj):
    pass
your_action_name.short_description = 'My Uniq Description'
your_action_name.short_description = 'short_description_func_name'

short_description function must have following signature:

def short_description_func_name(self, request, obj, parent_obj):

Css Class

Css Class are either custom function or simple string.

def your_action_name(self, request, obj, parent_obj):
    pass
your_action_name.css_class = 'my-css-class-name'
your_action_name.css_class = 'css_class_func_name'

css_class function must have following signature:

def css_class_func_name(self, request, obj, parent_obj):

Example

from django.contrib import admin
from inlines_actions import InlineActionsModelAdminMixin, InlineActionsMixin

from .models import Article1, Author1


class ArticleInline(
    InlineActionsMixin,
    admin.TabularInline,
):
    model = Article1
    inline_actions = ('make_published',)

    def make_published(self, request, obj, parent_obj):
        obj.is_published = not obj.is_published
        obj.save()

    def make_published_permission(self, request, obj, parent_obj):
        if not request.user.is_superuser:
            return False

    def make_published_short_description(self, request, obj, parent_obj):
        return 'Published Make'

    def make_published_css_class(self, request, obj, parent_obj):
        return 'some_class'

    make_published.permissions = ('make_published_permission', 'example_app:can_change_article')
    make_published.short_description = make_published_short_description
    make_published.css_class = make_published_css_class


class AuthorAdmin(
    InlineActionsModelAdminMixin,
    admin.ModelAdmin,
):
    inlines = (ArticleInline,)


admin.site.register(Author1, AuthorAdmin)

Tests

pip install requirements.txt
tox

Metadata

Release files for django-inlines-actions 0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-inlines-actions 0.4
File Size Uploaded Provenance Actions
django_inlines_actions-0.4.tar.gz 9.1 kB Without provenance Details for django_inlines_actions-0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-inlines-actions 0.4
File Interpreter ABI Platform Actions
django_inlines_actions-0.4-py3-none-any.whl Python 3 none any Details for django_inlines_actions-0.4-py3-none-any.whl

Total release size: 18.8 kB

Release files / django_inlines_actions-0.4.tar.gz

Download URL django_inlines_actions-0.4.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0bd13a482b4d313e14b6d57f2b4428c5f6e04d552479532823be32fafc90060c
BLAKE2b-256 checksum
How to use checksums
10d9de645bb4411d150c6baccaf214317c2d4e477d7b7e2e809c537f155e4fe0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

Release files / django_inlines_actions-0.4-py3-none-any.whl

Download URL django_inlines_actions-0.4-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d2344025a045b242b01ea0ec09028ba50cf7d21f0d149133497c95df112559f
BLAKE2b-256 checksum
How to use checksums
8d025388491c6f11de66429805c200778b55b985e0258f8b375c9ea60bb1d022
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

Security for django-inlines-actions 0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page