-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added remove delete selected chapter
- Loading branch information
Showing
5 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
How to add additional actions in Django admin? | ||
+++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
||
Django admin allows you to add additional actions which allow you to do bulk actions. | ||
You have been asked to add an action which will mark multiple :code:`Hero`s as immortal. | ||
You can do this by adding action a method to ModelAdmin | ||
and adding the method as string to :code:`actions`:: | ||
|
||
actions = ["mark_immortal"] | ||
|
||
def mark_immortal(self, request, queryset): | ||
queryset.update(is_immortal=True) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
How to remove the delete selected action in Django admin? | ||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
||
By default Django adds a `Delete Selected` action to the listview page. You have been asked to remove | ||
the action from the :code:`Hero` admin. | ||
|
||
The method :code:`ModelAdmin.get_actions` returns the actions shown. By overriding this method, to remove :code:`delete_selected` | ||
We can remove it form the dropdown. Your code looks like this with the changes.:: | ||
|
||
def get_actions(self, request): | ||
actions = super().get_actions(request) | ||
if 'delete_selected' in actions: | ||
del actions['delete_selected'] | ||
return actions | ||
|
||
And your admin looks like this | ||
|
||
.. image:: export_selected.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters