@@ -113,6 +113,37 @@ by adding a Django widget style `attrs` attribute::
113
113
'class': 'addlink',
114
114
}
115
115
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
+
116
147
117
148
Alternate Installation
118
149
``````````````````````
0 commit comments