@@ -15,14 +15,18 @@ Django Admin Actions? Well now they can be.
15
15
Quick-Start Guide
16
16
-----------------
17
17
18
- Install Django Object Actions::
18
+ Install Django Object Actions:
19
+
20
+ .. code-block :: bash
19
21
20
22
pip install django-object-actions
21
23
22
24
Add ``django_object_actions `` to your ``INSTALLED_APPS `` so Django can find our
23
25
templates.
24
26
25
- In your admin.py::
27
+ In your admin.py:
28
+
29
+ .. code-block :: python
26
30
27
31
from django_object_actions import DjangoObjectActions
28
32
@@ -46,7 +50,9 @@ an object instance instead of a queryset (see *Re-using Admin Actions* below).
46
50
47
51
Tool actions are exposed by putting them in a ``change_actions `` attribute in
48
52
your model admin. You can also add tool actions to the changelist views too.
49
- You'll get a queryset like a regular admin action::
53
+ You'll get a queryset like a regular admin action:
54
+
55
+ .. code-block :: python
50
56
51
57
from django_object_actions import DjangoObjectActions
52
58
@@ -74,8 +80,9 @@ Re-using Admin Actions
74
80
``````````````````````
75
81
76
82
If you would like a preexisting admin action to also be an change action, add
77
- the ``takes_instance_or_queryset `` decorator like::
83
+ the ``takes_instance_or_queryset `` decorator like:
78
84
85
+ .. code-block :: python
79
86
80
87
from django_object_actions import (DjangoObjectActions,
81
88
takes_instance_or_queryset)
@@ -94,23 +101,29 @@ Customizing Admin Actions
94
101
`````````````````````````
95
102
96
103
To give the action some a helpful title tooltip, add a ``short_description ``
97
- attribute, similar to how admin actions work::
104
+ attribute, similar to how admin actions work:
105
+
106
+ .. code-block :: python
98
107
99
108
def increment_vote (self , request , obj ):
100
109
obj.votes = obj.votes + 1
101
110
obj.save()
102
111
increment_vote.short_description = " Increment the vote count by one"
103
112
104
113
By default, Django Object Actions will guess what to label the button based on
105
- the name of the function. You can override this with a ``label `` attribute::
114
+ the name of the function. You can override this with a ``label `` attribute:
115
+
116
+ .. code-block :: python
106
117
107
118
def increment_vote (self , request , obj ):
108
119
obj.votes = obj.votes + 1
109
120
obj.save()
110
121
increment_vote.label = " Vote++"
111
122
112
123
If you need even more control, you can add arbitrary attributes to the buttons
113
- by adding a Django widget style `attrs ` attribute::
124
+ by adding a Django widget style `attrs ` attribute:
125
+
126
+ .. code-block :: python
114
127
115
128
def increment_vote (self , request , obj ):
116
129
obj.votes = obj.votes + 1
@@ -125,7 +138,9 @@ Programmatically Disabling Actions
125
138
You can programmatically disable registered actions by defining your own custom
126
139
``get_change_actions() `` method. In this example, certain actions only apply to
127
140
certain object states (i.e. You should not be able to close an company account
128
- if the account is already closed)::
141
+ if the account is already closed):
142
+
143
+ .. code-block :: python
129
144
130
145
def get_change_actions (self , request , object_id , form_url ):
131
146
actions = super (PollAdmin, self ).get_change_actions(request, object_id, form_url)
@@ -158,7 +173,9 @@ If you don't intend to use the template customizations at all, don't add
158
173
More Examples
159
174
-------------
160
175
161
- Making an action that links off-site::
176
+ Making an action that links off-site:
177
+
178
+ .. code-block :: python
162
179
163
180
def external_link (self , request , obj ):
164
181
from django.http import HttpResponseRedirect
@@ -197,7 +214,9 @@ This runs the example Django project in ``./example_project`` based on the
197
214
Development
198
215
-----------
199
216
200
- Getting started *(with virtualenvwrapper) *::
217
+ Getting started *(with virtualenvwrapper) *:
218
+
219
+ .. code-block :: bash
201
220
202
221
# get a copy of the code
203
222
git clone [email protected] :crccheck/django-object-actions.git
0 commit comments