@@ -7,32 +7,28 @@ If you've ever tried making your own admin object tools and you were
7
7
like me, you immediately gave up. Why can't they be as easy as making
8
8
Django Admin Actions? Well now they can be.
9
9
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
+ -----------------
22
12
23
13
Install Django Object Actions::
24
14
25
15
pip install django-object-actions
26
16
27
17
Add ``django_object_actions `` to your ``INSTALLED_APPS ``.
28
18
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', )
31
31
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> `_.
36
32
37
33
Usage
38
34
-----
@@ -42,13 +38,14 @@ Tools are defined just like defining actions as modeladmin methods, see:
42
38
actions <https://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/#actions-as-modeladmin-methods> `_
43
39
for examples and detailed syntax. You can return nothing or an http
44
40
response. 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).
48
42
49
43
Tools are exposed by putting them in an ``objectactions `` attribute in
50
44
your modeladmin like::
51
45
46
+ from django_object_actions import DjangoObjectActions
47
+
48
+
52
49
class MyModelAdmin(DjangoObjectActions, admin.ModelAdmin):
53
50
def toolfunc(self, request, obj):
54
51
pass
@@ -62,15 +59,18 @@ Normally, you would do something to the object and go back to the same
62
59
place, but if you return a HttpResponse, it will follow it (hey, just
63
60
like actions!).
64
61
62
+ If your admin modifies ``get_urls ``, ``render_change_form ``, or
63
+ ``change_form_template ``, you'll need to take extra care.
64
+
65
65
Re-using Admin Actions
66
66
``````````````````````
67
67
68
68
If you would like an admin action to also be an object tool, add the
69
69
``takes_instance_or_queryset `` decorator like::
70
70
71
71
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)
74
74
75
75
76
76
class RobotAdmin(DjangoObjectActions, admin.ModelAdmin):
@@ -83,16 +83,30 @@ If you would like an admin action to also be an object tool, add the
83
83
objectactions = ['tighten_lug_nuts']
84
84
actions = ['tighten_lug_nuts']
85
85
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
+
86
98
87
99
Limitations
88
- ~~~~~~~~~~~
100
+ -----------
89
101
90
102
1. ``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.
91
104
92
105
2. If you provide your own custom ``change_form.html ``, you'll also need to
93
106
manually copy in the relevant bits of `our change form
94
107
<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.
96
110
97
111
Development
98
112
-----------
@@ -107,12 +121,23 @@ Getting started *(with virtualenvwrapper)*::
107
121
pip install -r requirements-dev.txt
108
122
export DJANGO_SETTINGS_MODULE=example_project.settings
109
123
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
114
128
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.
117
130
118
131
Various 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