@@ -7,32 +7,28 @@ If you've ever tried making your own admin object tools and you were
77like me, you immediately gave up. Why can't they be as easy as making
88Django Admin Actions? Well now they can be.
99
10- Similar Packages
11- ~~~~~~~~~~~~~~~~
12-
13- Django Object Actions is very similar to
14- `django-object-tools <https://github.com/praekelt/django-object-tools >`_,
15- but does not require messing with your urls.py, does not do anything
16- special with permissions, and uses the same patterns as making `admin
17- actions <https://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/#actions-as-modeladmin-methods> `_
18- in Django.
19-
20- Installation
21- ------------
10+ Quick-Start Guide
11+ -----------------
2212
2313Install Django Object Actions::
2414
2515 pip install django-object-actions
2616
2717Add ``django_object_actions `` to your ``INSTALLED_APPS ``.
2818
29- Alternate Installation
30- ~~~~~~~~~~~~~~~~~~~~~~
19+ In your admin.py::
20+
21+ from django_object_actions import DjangoObjectActions
22+
23+
24+ class ArticleAdmin(DjangoObjectActions, admin.ModelAdmin):
25+ def publish_this(self, request, obj):
26+ publish_obj(obj)
27+ publish_this.label = "Publish" # optional
28+ publish_this.short_description = "Submit this article to The Texas Tribune" # optional
29+
30+ objectactions = ('publish_this', )
3131
32- You don't have to add this to ``INSTALLED_APPS ``, all you need to to do is copy
33- the template ``django_object_actions/change_form.html `` some place Django's
34- template loader `will find it
35- <https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs> `_.
3632
3733Usage
3834-----
@@ -42,13 +38,14 @@ Tools are defined just like defining actions as modeladmin methods, see:
4238actions <https://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/#actions-as-modeladmin-methods> `_
4339for examples and detailed syntax. You can return nothing or an http
4440response. The major difference being the functions you write will take
45- an object instance instead of a queryset::
46-
47- def toolfunc(self, request, obj)
41+ an object instance instead of a queryset (see *Re-using Admin Actions * below).
4842
4943Tools are exposed by putting them in an ``objectactions `` attribute in
5044your modeladmin like::
5145
46+ from django_object_actions import DjangoObjectActions
47+
48+
5249 class MyModelAdmin(DjangoObjectActions, admin.ModelAdmin):
5350 def toolfunc(self, request, obj):
5451 pass
@@ -62,15 +59,18 @@ Normally, you would do something to the object and go back to the same
6259place, but if you return a HttpResponse, it will follow it (hey, just
6360like actions!).
6461
62+ If your admin modifies ``get_urls ``, ``render_change_form ``, or
63+ ``change_form_template ``, you'll need to take extra care.
64+
6565Re-using Admin Actions
6666``````````````````````
6767
6868If you would like an admin action to also be an object tool, add the
6969``takes_instance_or_queryset `` decorator like::
7070
7171
72- from django_object_actions import DjangoObjectActions
73- from django_object_actions.utils import takes_instance_or_queryset
72+ from django_object_actions import ( DjangoObjectActions,
73+ takes_instance_or_queryset)
7474
7575
7676 class RobotAdmin(DjangoObjectActions, admin.ModelAdmin):
@@ -83,16 +83,30 @@ If you would like an admin action to also be an object tool, add the
8383 objectactions = ['tighten_lug_nuts']
8484 actions = ['tighten_lug_nuts']
8585
86+ Alternate Installation
87+ ``````````````````````
88+
89+ You don't have to add this to ``INSTALLED_APPS ``, all you need to to do is copy
90+ the template ``django_object_actions/change_form.html `` some place Django's
91+ template loader `will find it
92+ <https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs> `_.
93+
94+ If you don't intend to use the template customizations at all, don't add
95+ ``django_object_actions `` to your ``INSTALLED_APPS `` at all and use
96+ ``BaseDjangoObjectActions `` instead of ``DjangoObjectActions ``.
97+
8698
8799Limitations
88- ~~~~~~~~~~~
100+ -----------
89101
901021. ``django-object-actions `` expects functions to be methods of the model admin.
103+ While Django gives you a lot more options for their admin actions.
91104
921052. If you provide your own custom ``change_form.html ``, you'll also need to
93106 manually copy in the relevant bits of `our change form
94107 <https://github.com/texastribune/django-object-actions/blob/master/django_obj
95- ect_actions/templates/django_object_actions/change_form.html> `_.
108+ ect_actions/templates/django_object_actions/change_form.html> `_. You can also
109+ use ``from django_object_actions import BaseDjangoObjectActions `` instead.
96110
97111Development
98112-----------
@@ -107,12 +121,23 @@ Getting started *(with virtualenvwrapper)*::
107121 pip install -r requirements-dev.txt
108122 export DJANGO_SETTINGS_MODULE=example_project.settings
109123 add2virtualenv .
110- # start doing stuff
111- make test
112- make resetdb
113- python example_project/manage.py runserver
124+ make test # run test suite
125+ tox # run full test suite, requires more setup
126+ make resetdb # reset the example db
127+ python example_project/manage.py runserver # run debug server
114128
115- The fixtures will create a user, admin:admin, you can use to log in
116- immediately.
129+ The fixtures will create a user, admin:admin, you can use to log in immediately.
117130
118131Various helpers are available as make commands.
132+
133+
134+ Similar Packages
135+ ----------------
136+
137+ Django Object Actions is very similar to
138+ `django-object-tools <https://github.com/praekelt/django-object-tools >`_,
139+ but does not require messing with your urls.py, does not do anything
140+ special with permissions, and uses the same patterns as making `admin
141+ actions <https://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/#actions-as-modeladmin-methods> `_
142+ in Django.
143+
0 commit comments