Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update README style #157

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 16 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -30,18 +27,17 @@ class ArticleAdmin(DjangoObjectActions, admin.ModelAdmin):
publish_obj(obj)

change_actions = ('publish_this', )
changelist_actions = ('...', )
```

## 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
Expand Down Expand Up @@ -72,7 +68,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:

Expand All @@ -92,7 +88,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.
Expand Down Expand Up @@ -191,9 +187,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:

Expand All @@ -203,9 +197,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
Expand All @@ -218,25 +210,19 @@ 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

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:

Expand All @@ -256,9 +242,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).
Expand Down
7 changes: 3 additions & 4 deletions django_object_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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')
Expand All @@ -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):
Expand Down