Skip to content

jsocol/django-adminplus

Repository files navigation

Django AdminPlus

AdminPlus aims to be the smallest possible extension to the excellent Django admin component that lets you add admin views that are not tied to models.

There are packages out there, like Nexus and django-admin-tools that replace the entire admin. Nexus supports adding completely new "modules" (the Django model admin is a default module) but there seems to be a lot of boiler plate code to do it. django-admin-tools does not, as far as I can tell, support adding custom pages.

All AdminPlus does is allow you to add simple custom views (well, they can be as complex as you like!) without mucking about with hijacking URLs, and providing links to them right in the admin index.

image

Installing AdminPlus

Install from PyPI with pip:

Or get AdminPlus from GitHub with pip:

And add adminplus to your installed apps, and replace django.contrib.admin with django.contrib.admin.apps.SimpleAdminConfig:

To use AdminPlus in your Django project, you'll need to replace django.contrib.admin.site, which is an instance of django.contrib.admin.sites.AdminSite. I recommend doing this in urls.py right before calling admin.autodiscover():

Congratulations! You're now using AdminPlus.

Using AdminPlus

So now that you've installed AdminPlus, you'll want to use it. AdminPlus is 100% compatible with the built in admin module, so if you've been using that, you shouldn't have to change anything.

AdminPlus offers a new function, admin.site.register_view, to attach arbitrary views to the admin:

Now my_view will be accessible at admin/somepath and there will be a link to it in the Custom Views section of the admin index.

You can also use register_view as a decorator:

register_view takes some optional arguments:

All registered views are wrapped in admin.site.admin_view.

Note

Views with URLs that match auto-discovered URLs (e.g. those created via ModelAdmins) will override the auto-discovered URL.