ModelAdmin.get_actions(request)
[source]
Finally, you can conditionally enable or disable actions on a per-request (and hence per-user basis) by overriding ModelAdmin.get_actions()
.
This returns a dictionary of actions allowed. The keys are action names, and the values are (function, name, short_description)
tuples.
Most of the time you’ll use this method to conditionally remove actions from the list gathered by the superclass. For example, if I only wanted users whose names begin with ‘J’ to be able to delete objects in bulk, I could do the following:
1 2 3 4 5 6 7 8 9 | class MyModelAdmin(admin.ModelAdmin): ... def get_actions( self , request): actions = super (MyModelAdmin, self ).get_actions(request) if request.user.username[ 0 ].upper() ! = 'J' : if 'delete_selected' in actions: del actions[ 'delete_selected' ] return actions |
Please login to continue.