Skip to main content

Django app enabling painless creation of additional admin object tools.

Project description

Django Object Tools

Django app enabling painless creation of additional admin object tools.

This packages is part of the larger Jmbo project.


  1. Install or add django-object-tools to your python path.

  2. Add object_tools to your INSTALLED_APPS setting. django-object-tools overrides certain admin templates so you have to add it before django.contrib.admin.

  3. Call object tool’s autodiscover method. This works in a similar fashion as Django’s admin; discovering which tools to render in admin. You can do this in any module that is called during initialization but we recommend doing it in, as illustrated in the next point.

  4. Hook up URLConf. Do this by pointing a given URL at the tools.urls method. In this example, we register the default Tools instance at the URL /object-tools/:

    from django.conf.urls.defaults import *
    import object_tools
    urlpatterns = patterns('',
        (r'^object-tools/', include(,
  5. Obviously Django Admin itself needs to be installed, as described here.

  6. Remember to run syncdb whenever you install new tools to setup permissions.


django-object-tools itself doesn’t do much in terms of providing useful tools. Its purpose is to simplify creation and integration of custom tools delivered by other Django applications. To that end it takes care of the messy details like permissions and admin template integration so you can focus on the fun stuff.

As an example lets create a tool allowing you to delete all objects. Yes this is a bit convoluted but it’s a good toy example for illustration purposes. Have a look at django-export and django-order for examples of real world tools leveraging django-object-tools.

Firstly create a Django app folder structure as per usual, with the root directory named delete, including a file called It should look as follows:


Edit to look like this:

from django.contrib.admin.actions import delete_selected
import object_tools

class Delete(object_tools.ObjectTool):
    name = 'delete'
    label = 'Delete all'

    def view(self, request, extra_context=None):
        queryset = self.model.objects.all()
        response = delete_selected(self.modeladmin, request, queryset)
        if response:
            return response
            return self.modeladmin.changelist_view(request)

Let’s go through that line by line:

  1. object_tools behaves similarly to Django’s admin allowing you to explicitly register tools, see line 17. It also provides the ObjectTool base class.
  1. import delete_selected method provided by Django. This method will do all the heavy lifting.
  1. Create a tool class inheriting from object_tools.ObjectTool. All object tools have to inherit from object_tools.ObjectTool. ObjectTool provides various methods to simplify creation of tools. See for more details.
  2. Set tool name to delete. This has to be a unique name identifying the tool. This is used to uniquely identify the tool internally and for instance to setup permissions.
  3. Set label to Delete all. The label is displayed within admin and not the name, thus allowing you to specify a more verbose, user friendly label.
  1. Implement view method. This is the brains of your tool. The view method is called when the user executes your tool, so your tool logic would go here. This can be any view like code, as long as it returns an HttpResponse object. In this case we wrap Django’s built-in delete_selected to provide the form, logic and template code to perform the actual delete.
  1. Register the tool with object_tools, thus enabling its display in admin.

To enable the tool add delete to your INSTALLED_APPS setting.

Now when you navigate to the change list view of any model you’ll find the delete all object tool in the upper right hand corner.

Clicking on the Delete all tool fires off the view and proceeds with deleting objects as per usual.

Note: django-object-tools adds per tool permissions to the built-in set of default Django permissions. So in this example only superusers or users who have the the Can delete <model> permission will be able to see and use the tool. If you can’t see or use a particular tool make sure the authenticated user has the required permissions to do so.


Praekelt Foundation

  • Shaun Sephton



#. Fixed campatability issues with newer versions of Django. This however may not be backward compatable with versions of Django earlier than 1.4.


  1. Pass context to object_tools tag. Thanks slafs


  1. Corrected ‘str’ object has no attribute ‘has_perm’ bug #7.


  1. Remove usage of ‘ADMIN_STATIC_PREFIX’ in templates for move to Django 1.4.


  1. Better packaging.

0.0.3 (2011-09-15)

  1. Correctly resolve title.

0.0.1 (2011-07-22)

  1. Initial release.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django-object-tools-1.0.0.tar.gz (12.3 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page