How to add button next to Add User button in Django Admin Site

  1. Create a template in you template folder: admin/YOUR_APP/YOUR_MODEL/change_list.html
  2. 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 %}
    
  3. Create a view function in YOUR_APP/admin.py and secure it with annotation

    from 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"])
    
  4. Add new url into YOUR_APP/admin.py to url config for admin model

    from 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 ;)