How to add button next to Add User button in Django Admin Site
- Create a template in you template folder: admin/YOUR_APP/YOUR_MODEL/change_list.html
Put this into that template
{% extends "admin/change_list.html" %} {% block object-tools-items %} {{ block.super }} <li> <a href="export/" class="grp-state-focus addlink">Export</a> </li> {% endblock %}
Create a view function in
YOUR_APP/admin.py
and secure it with annotationfrom django.contrib.admin.views.decorators import staff_member_required @staff_member_required def export(self, request): ... do your stuff ... return HttpResponseRedirect(request.META["HTTP_REFERER"])
Add new url into
YOUR_APP/admin.py
to url config for admin modelfrom django.conf.urls import patterns, include, url class YOUR_MODELAdmin(admin.ModelAdmin): ... list def stuff ... def get_urls(self): urls = super(MenuOrderAdmin, self).get_urls() my_urls = patterns("", url(r"^export/$", export) ) return my_urls + urls
Enjoy ;)