Package: django-object-tools
Django Object ToolsDjango app enabling painless creation of additional admin object tools.ContentsDjango Object ToolsRequirementsInstallationUsageAUTHORSChangelog2.001.111.91.0.31.0.21.0.11.0.00.0.70.0.60.0.50.0.40.0.3 (2011-09-15)0.0.1 (2011-07-22)RequirementsPython 2.7, 3.5-3.7Django 1.11, 2.0, 2.1InstallationInstall or adddjango-object-toolsto your python path.Addobject_toolsto yourINSTALLED_APPSsetting.django-object-toolsoverrides certain admin templates so you have to add itbeforedjango.contrib.admin.Hook up URLConf. Do this by pointing a given URL at thetools.urlsmethod. In this example, we register the defaultToolsinstanceobject_tools.toolsat the URL/object-tools/:# urls.pyfromdjango.conf.urls.defaultsimport*fromdjango.conf.urlsimporturlimportobject_toolsurlpatterns=[path('object-tools/',object_tools.tools.urls)]Obviously Django Admin itself needs to be installed, as describedhere.Remember to runmigratewhenever you install new tools to setup permissions.Usagedjango-object-toolsitself 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 atdjango-exportanddjango-orderfor examples of real world tools leveragingdjango-object-tools.Firstly create a Django app folder structure as per usual, with the root directory nameddelete, including a file calledtools.py. It should look as follows:delete/
    __init__.py
    tools.pyEdittools.pyto look like this:fromdjango.contrib.admin.actionsimportdelete_selectedfromdjango.contrib.admin.sitesimportsiteimportobject_toolsclassDelete(object_tools.ObjectTool):name='delete'label='Delete all'defview(self,request,extra_context=None):queryset=self.model.objects.all()modeladmin=site._registry.get(self.model)response=delete_selected(modeladmin,request,queryset)ifresponse:returnresponseelse:returnmodeladmin.changelist_view(request)object_tools.tools.register(Delete)Let’s go through that line by line:object_toolsbehaves similarly to Django’s admin allowing you to explicitly register tools, see line 17. It also provides theObjectToolbase class.importdelete_selectedmethod provided by Django. This method will do all the heavy lifting.Create a tool class inheriting fromobject_tools.ObjectTool. All object tools have to inherit fromobject_tools.ObjectTool.ObjectToolprovides various methods to simplify creation of tools. Seeobject_tools.options.pyfor more details.Set tool name todelete. 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.Set label toDelete all. The label is displayed within admin and not the name, thus allowing you to specify a more verbose, user friendly label.Implementviewmethod. This is the brains of your tool. Theviewmethod 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 anHttpResponseobject. In this case we wrap Django’s built-indelete_selectedto provide the form, logic and template code to perform the actual delete.Register the tool withobject_tools, thus enabling its display in admin.To enable the tool adddeleteto yourINSTALLED_APPSsetting.Now when you navigate to the change list view of any model you’ll find thedelete allobject tool in the upper right hand corner.Clicking on theDelete alltool fires off the view and proceeds with deleting objects as per usual.Note:django-object-toolsadds per tool permissions to the built-in set of default Django permissions. So in this example only superusers or users who have the theCan 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.AUTHORSPraekelt ConsultingShaun SephtonChangelog2.00Django 2.0 & 2.1 compatibility.Added coverallsDeprecated support for versions below Django 1.11.1.11Django 1.11 compatibility.Deprecated support for versions below Django 1.9.1.9Django 1.9 compatibility.1.0.3Fixed Django 1.4 templatetag issues.1.0.2Django 1.7 compatibility.1.0.1Fixed compatibility issues with Django 1.5+ url templatetags.1.0.0#. Fixed compatibility issues with newer versions of Django. This however may not be
backward compatible with versions of Django earlier than 1.4.0.0.7Pass context to object_tools tag. Thanksslafs0.0.6Corrected ‘str’ object has no attribute ‘has_perm’ bug#7.0.0.5Remove usage of ‘ADMIN_STATIC_PREFIX’ in templates for move to Django 1.4.0.0.4Better packaging.0.0.3 (2011-09-15)Correctly resolve title.0.0.1 (2011-07-22)Initial release.