Automatically generates Django admin actions based on your model's fields
Project description
Django Auto Actions
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:
- Using AutoActionsMixin (recommended way)
from django.contrib.admin import ModelAdmin
from django_auto_actions import AutoActionsMixin
@admin.register(YourModel)
class YourModelAdmin(AutoActionsMixin, ModelAdmin):
...
- 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:
And will display a success message like this:
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
- Félix Gravel — @Flexonze