From cc638fa208220238e5429dc12b6f9d4745c62855 Mon Sep 17 00:00:00 2001 From: crccheck Date: Tue, 22 Aug 2023 15:29:18 +0000 Subject: [PATCH 1/3] markdown autoformat --- README.md | 47 +++++++++++++++-------------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index da479d0..177b85d 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,11 @@ -Django Object Actions -===================== +# Django Object Actions [![CI](https://github.com/crccheck/django-object-actions/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/crccheck/django-object-actions/actions/workflows/ci.yml?query=branch%3Amaster) If you've ever tried making admin object tools you may have thought, "why can't this be as easy as making Django Admin Actions?" Well now they can be. - -Quick-Start Guide ------------------ +## Quick-Start Guide Install Django Object Actions: @@ -32,16 +29,14 @@ class ArticleAdmin(DjangoObjectActions, admin.ModelAdmin): change_actions = ('publish_this', ) ``` +## Usage -Usage ------ - -Defining new &*tool actions* is just like defining regular [admin actions]. The +Defining new &_tool actions_ is just like defining regular [admin actions]. The major difference is the functions for `django-object-actions` will take an -object instance instead of a queryset (see *Re-using Admin Actions* below). +object instance instead of a queryset (see _Re-using Admin Actions_ below). -*Tool actions* are exposed by putting them in a `change_actions` attribute in -your `admin.ModelAdmin`. You can also add *tool actions* to the main changelist +_Tool actions_ are exposed by putting them in a `change_actions` attribute in +your `admin.ModelAdmin`. You can also add _tool actions_ to the main changelist views too. There, you'll get a queryset like a regular [admin action][admin actions]: ```python @@ -72,7 +67,7 @@ you'll need to take extra care because `django-object-actions` uses them too. ### Re-using Admin Actions -If you would like a preexisting admin action to also be an *object action*, add +If you would like a preexisting admin action to also be an _object action_, add the `takes_instance_or_queryset` decorator to convert object instances into a queryset and pass querysets: @@ -92,7 +87,7 @@ class RobotAdmin(DjangoObjectActions, admin.ModelAdmin): [admin actions]: https://docs.djangoproject.com/en/stable/ref/contrib/admin/actions/ -### Customizing *Object Actions* +### Customizing _Object Actions_ To give the action some a helpful title tooltip, you can use the `action` decorator and set the description argument. @@ -191,9 +186,7 @@ If you don't intend to use the template customizations at all, don't add `django_object_actions` to your `INSTALLED_APPS` at all and use `BaseDjangoObjectActions` instead of `DjangoObjectActions`. - -More Examples -------------- +## More Examples Making an action that links off-site: @@ -203,9 +196,7 @@ def external_link(self, request, obj): return HttpResponseRedirect(f'https://example.com/{obj.id}') ``` - -Limitations ------------ +## Limitations 1. `django-object-actions` expects functions to be methods of the model admin. While Django gives you a lot more options for their admin @@ -218,15 +209,11 @@ Limitations your own actions irregardless of what this provides. Better default security is planned for the future. - -Python and Django compatibility -------------------------------- +## Python and Django compatibility See [`ci.yml`](./.github/workflows/ci.yml) for which Python and Django versions this supports. - -Demo Admin & Docker images --------------------------- +## Demo Admin & Docker images You can try the demo admin against several versions of Django with these Docker images: https://hub.docker.com/r/crccheck/django-object-actions/tags @@ -234,9 +221,7 @@ images: https://hub.docker.com/r/crccheck/django-object-actions/tags This runs the example Django project in `./example_project` based on the "polls" tutorial. `admin.py` demos what you can do with this app. - -Development ------------ +## Development Getting started: @@ -256,9 +241,7 @@ view the `Makefile` to see what other things you can do. Some commands assume you are in the virtualenv. If you see "ModuleNotFoundError"s, try running `poetry shell` first. - -Similar Packages ----------------- +## Similar Packages If you want an actions menu for each row of your changelist, check out [Django Admin Row Actions](https://github.com/DjangoAdminHackers/django-admin-row-actions). From bed294e7541edb3369bdd71f05271457843d47f0 Mon Sep 17 00:00:00 2001 From: crccheck Date: Wed, 23 Aug 2023 06:25:54 +0000 Subject: [PATCH 2/3] show changelist_actions earlier in docs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 177b85d..a775244 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ class ArticleAdmin(DjangoObjectActions, admin.ModelAdmin): publish_obj(obj) change_actions = ('publish_this', ) + changelist_actions = ('...', ) ``` ## Usage From 6696d5fcb61974a9c9721477c0789e664739881e Mon Sep 17 00:00:00 2001 From: crccheck Date: Wed, 23 Aug 2023 06:29:59 +0000 Subject: [PATCH 3/3] update admin.action link to stable instead of dev url --- django_object_actions/utils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/django_object_actions/utils.py b/django_object_actions/utils.py index 095ab11..92ada06 100644 --- a/django_object_actions/utils.py +++ b/django_object_actions/utils.py @@ -317,7 +317,7 @@ def action( function=None, *, permissions=None, description=None, label=None, attrs=None ): """ - Conveniently add attributes to an action function:: + Conveniently add attributes to an action function: @action( permissions=['publish'], @@ -328,7 +328,7 @@ def make_published(self, request, queryset): queryset.update(status='p') This is equivalent to setting some attributes (with the original, longer - names) on the function directly:: + names) on the function directly: def make_published(self, request, queryset): queryset.update(status='p') @@ -337,8 +337,7 @@ def make_published(self, request, queryset): make_published.label = 'Publish' This is the django-object-actions equivalent of - https://docs.djangoproject.com - /en/dev/ref/contrib/admin/actions/#django.contrib.admin.action + https://docs.djangoproject.com/en/stable/ref/contrib/admin/actions/#django.contrib.admin.action """ def decorator(func):