#
# Copy from django source template admin/change_form.html to your app template dir
# And replace the block
# "./your_app/templates/admin/change_form.html"
{% block object-tools %}
{% if change %}{% if not is_popup %}
{% endif %}{% endif %}
{% endblock %}
#
# Add this code to your models.py
#
def _ban_user(request, id):
from django.http.response import HttpResponse
return HttpResponse(u'User %s Banned! :)' % id)
class MyUserAdmin(UserAdmin):
buttons = [
{
'url': '_ban_action',
'textname': 'Ban user',
'func': _ban_user,
'confirm': u'Do you want ban this user?'
},
]
def change_view(self, request, object_id, form_url='', extra_context={}):
extra_context['buttons'] = self.buttons
return super(MyUserAdmin, self).change_view(request, object_id, form_url, extra_context=extra_context)
def get_urls(self):
from django.conf.urls import patterns, url, include
urls = super(MyUserAdmin, self).get_urls()
my_urls = list( (url(r'^(.+)/%(url)s/$' % b, self.admin_site.admin_view(b['func'])) for b in self.buttons) )
return my_urls + urls
# Enjoy!