Skip to content

Commit

Permalink
Added action buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
shabda committed Feb 20, 2018
1 parent 560eb70 commit 1acfb61
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions docs/action_buttons.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ However, they want to be able to change their mind and say all heroes are immort

You have been absked to add two buttons - One which makes all heroes mortal, and one which makes all immortal. Since it affects all heores irrespective of the selection, this needs to be a separate button, not an action dropdown.

First, we will change the template on the :code:`HeroAdmin` so we can add two buttons.:
First, we will change the template on the :code:`HeroAdmin` so we can add two buttons.::

@admin.register(Hero)
class HeroAdmin(admin.ModelAdmin, ExportCsvMixin):
change_list_template = "entities/heroes_changelist.html"

Then we will override the :code:`get_urls`, and add the :code:`set_immortal` and :code:`set_mortal` methods on the model admin. They will serve as the two view methods.
Then we will override the :code:`get_urls`, and add the :code:`set_immortal` and :code:`set_mortal` methods on the model admin. They will serve as the two view methods.::

def get_urls(self):
urls = super().get_urls()
Expand All @@ -32,7 +32,7 @@ Then we will override the :code:`get_urls`, and add the :code:`set_immortal` and
self.message_user(request, "All heroes are now mortal")
return HttpResponseRedirect("../")

Finally, we create the :code:`entities/heroes_changelist.html` template by extending the :code:`admin/change_list.html`.
Finally, we create the :code:`entities/heroes_changelist.html` template by extending the :code:`admin/change_list.html`.::


{% extends 'admin/change_list.html' %}
Expand Down
2 changes: 2 additions & 0 deletions docs/many_to_many.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
How to show many to many fields on listview page?
===========================================================


2 changes: 1 addition & 1 deletion heroes_and_monsters/entities/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HeroAdmin(admin.ModelAdmin, ExportCsvMixin):

# fields = ["headshot_image"]

readonly_fields = ["father", "mother", "spouse", "headshot_image"]
readonly_fields = ["headshot_image"]

change_list_template = "entities/heroes_changelist.html"

Expand Down

0 comments on commit 1acfb61

Please sign in to comment.