Admin¶
CWF provides the ability to add buttons to your admin pages with relative ease.
As long as you have made the CWF templates
available and your admin class subclasses
cwf.admin.ButtonAdmin
, then you can give your admin a list of buttons that
are rendered on your admin page and call particular functions on your admin
class when they are pressed.
How it works¶
There are two things that are necessary to make extra buttons work on the admin:
- Modified urls for that admin
Django admin classes have a
urls
function that is used to generate the urlpatterns for that particular admin.The
cwf.admin.ButtonAdmin
class overrides this function to add urls for each button that will figure out what function on the admin class to use when that url is requested.- Display buttons to press
cwf.admin.ButtonAdmin
will add the buttons you put onto the class into the context when rendering the template for the changeform and the changelist views.Then, as long as the templates you are using are aware of these buttons, then they may be displayed.
Usage is something like:
from django.http import HttpResponse
from django.contrib import admin
from cwf.admin import ButtonAdmin, Button, ButtonGroup
from webthing.models import AwesomeModel
class AwesomeAdmin(ButtonAdmin):
[..]
buttons = (
Button("one", "First")
, Button("two", "Second")
, ButtonGroup("Other",
( Button('three', "Third"
, description="The third button"
)
, Button('four', "Fourth"
, description="The fourth button"
)
)
)
def tool_one(self, request, ball, button):
return HttpResponse("one")
def tool_two(self, request, ball, button):
return HttpResponse("two")
def tool_three(self, request, ball, button):
return HttpResponse("three")
def tool_four(self, request, ball, button):
return HttpResponse("four")
[..]
admin.site.register(AwesomeModel, AwesomeAdmin)
See Buttons for what options are available.