Skip to content

Commit 399affa

Browse files
bashucrccheck
authored andcommitted
docs: add syntax highlighting (#102)
1 parent 42055a3 commit 399affa

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

README.rst

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ Django Admin Actions? Well now they can be.
1515
Quick-Start Guide
1616
-----------------
1717

18-
Install Django Object Actions::
18+
Install Django Object Actions:
19+
20+
.. code-block:: bash
1921
2022
pip install django-object-actions
2123
2224
Add ``django_object_actions`` to your ``INSTALLED_APPS`` so Django can find our
2325
templates.
2426

25-
In your admin.py::
27+
In your admin.py:
28+
29+
.. code-block:: python
2630
2731
from django_object_actions import DjangoObjectActions
2832
@@ -46,7 +50,9 @@ an object instance instead of a queryset (see *Re-using Admin Actions* below).
4650

4751
Tool actions are exposed by putting them in a ``change_actions`` attribute in
4852
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
5056
5157
from django_object_actions import DjangoObjectActions
5258
@@ -74,8 +80,9 @@ Re-using Admin Actions
7480
``````````````````````
7581

7682
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:
7884

85+
.. code-block:: python
7986
8087
from django_object_actions import (DjangoObjectActions,
8188
takes_instance_or_queryset)
@@ -94,23 +101,29 @@ Customizing Admin Actions
94101
`````````````````````````
95102

96103
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
98107
99108
def increment_vote(self, request, obj):
100109
obj.votes = obj.votes + 1
101110
obj.save()
102111
increment_vote.short_description = "Increment the vote count by one"
103112
104113
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
106117
107118
def increment_vote(self, request, obj):
108119
obj.votes = obj.votes + 1
109120
obj.save()
110121
increment_vote.label = "Vote++"
111122
112123
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
114127
115128
def increment_vote(self, request, obj):
116129
obj.votes = obj.votes + 1
@@ -125,7 +138,9 @@ Programmatically Disabling Actions
125138
You can programmatically disable registered actions by defining your own custom
126139
``get_change_actions()`` method. In this example, certain actions only apply to
127140
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
129144
130145
def get_change_actions(self, request, object_id, form_url):
131146
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
158173
More Examples
159174
-------------
160175

161-
Making an action that links off-site::
176+
Making an action that links off-site:
177+
178+
.. code-block:: python
162179
163180
def external_link(self, request, obj):
164181
from django.http import HttpResponseRedirect
@@ -197,7 +214,9 @@ This runs the example Django project in ``./example_project`` based on the
197214
Development
198215
-----------
199216

200-
Getting started *(with virtualenvwrapper)*::
217+
Getting started *(with virtualenvwrapper)*:
218+
219+
.. code-block:: bash
201220
202221
# get a copy of the code
203222
git clone [email protected]:crccheck/django-object-actions.git

0 commit comments

Comments
 (0)