Flexonze / django-auto-actions

Automatically generates basic Django admin actions based on your models' fields
MIT License
18 stars 4 forks source link

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

Running ruff (linting & formatting)

pip install -r requirements.txt
ruff check

You can also run ruff fix to automatically fix some of the issues.

ruff check --fix

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

License

MIT © Félix Gravel