Skip to content

Commit 75f3111

Browse files
committed
Merge pull request #19 from maestrofjp/master
Documented example of a custom get_object_actions() method
2 parents 635778c + 4faadde commit 75f3111

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: README.rst

+31
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,37 @@ by adding a Django widget style `attrs` attribute::
113113
'class': 'addlink',
114114
}
115115

116+
Programmatically Enabling Object Admin Actions
117+
``````````````````````````````````````````````
118+
119+
You can programatically enable and disable registered object actions by defining
120+
your own custom ``get_object_actions()`` method. In this example, certain actions
121+
only apply to certain object states (i.e. You should not be able to close an company
122+
account if the account is already closed)::
123+
124+
def get_object_actions(self, request, context, **kwargs):
125+
objectactions = []
126+
127+
# Actions cannot be applied to new objects (i.e. Using "add" new obj)
128+
if 'original' in context:
129+
# The obj to perform checks against to determine object actions you want to support
130+
obj = context['original']
131+
132+
if not obj.verified:
133+
objectactions.extend(['verify_company_account_action', ])
134+
135+
status_code = obj.status_code
136+
137+
if status_code == 'Active':
138+
objectactions.extend(['suspend_company_account_action', 'close_company_account_action', ])
139+
elif status_code == 'Suspended':
140+
objectactions.extend(['close_company_account_action', 'reactivate_company_account_action', ])
141+
elif status_code == 'Closed':
142+
objectactions.extend(['reactivate_company_account_action', ])
143+
144+
return objectactions
145+
146+
116147

117148
Alternate Installation
118149
``````````````````````

0 commit comments

Comments
 (0)