I am working on Django Project where I need to extract the list of user to excel from the Django Admin's Users Screen. I added actions
variable to my Sample Class for getting the CheckBox before each user's id.
class SampleClass(admin.ModelAdmin): actions =[make_published]
Action make_published is already defined. Now I want to append another button next to Add user
button as shown in fig. . But I dont know how can I achieve this this with out using new template. I want to use that button for printing selected user data to excel. Thanks, please guide me.
Django >1.8 Another option for adding a button would be to use django-object-actions. First, install it: pip install django-object-actions . (Also add django-object-actions to your requirements file if you have one). Second, add django_object_actions to your INSTALLED_APPS .
Django Admin is one of the most important tools of Django. It's a full-fledged application with all the utilities a developer need. Django Admin's task is to provide an interface to the admin of the web project. Django's Docs clearly state that Django Admin is not made for frontend work.
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 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"])
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 ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With