Skip to main content

Automatically generates Django admin actions based on your model's fields

Project description

Django Auto Actions

PyPI PyPI - Python Version PyPI - License Ruff Coverage

Automatically generates basic Django admin actions based on your models' fields

Installation

Install the package using pip

pip install django-auto-actions

Usage

There are two ways to integrate django-auto-actions into your project:

  1. Using AutoActionsMixin (recommended way)
from django.contrib.admin import ModelAdmin
from django_auto_actions import AutoActionsMixin


@admin.register(YourModel)
class YourModelAdmin(AutoActionsMixin, ModelAdmin):
    ...
  1. Using AutoActionsModelAdmin instead of ModelAdmin
from django_auto_actions import AutoActionsModelAdmin


@admin.register(YourModel)
class YourModelAdmin(AutoActionsModelAdmin):
    ...

With either method, django-auto-actions will automatically generate admin actions for your model's BooleanFields, DateTimeFields, DateFields and TimeFields.

To exclude certain fields from having automatic admin actions generated, set the exclude_auto_actions class-level attribute.

@admin.register(YourModel)
class YourModelAdmin(AutoActionsMixin, ModelAdmin):
    exclude_auto_actions = ["is_example", "created_at"]

Example

Here's an example of what it might look like for a simple Homework model:
Example auto actions
And will display a success message like this:
Example success message

Running Tests

pip install -r requirements.txt
docker compose up -d
python runtests.py

Support & Contributing

If you like it, please consider giving this project a star. If you’re using the package, let me know! You can also create an issue for any problems or suggestions. PRs are always welcome!

Authors

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page