Easily link custom admin views and direct URLs into the Django admin
While "the admin is not your app", it is often useful to be able to easily add a bit of functionality to the admin for internal staff or other internal users that are tech savvy enough to use the admin.
There are several third party project such as
AdminPlus_, but they require the user to redefine the Admin.site object. This is fine for developers who are setting up a Django project, but not ideal for developers who are writing third party tools for other developers to use in their projects.
django-admin-views attempts to solve this by simply overriding the admin templates to provide two features:
pip install django-admin-views
settings.pybefore admin site, i.e.
If you are using a custom Admin Site, you'll need to configure the
ADMIN_VIEWS_SITEsetting to point to your admin site instance::
ADMIN_VIEWS_SITE = 'myproject.admin.admin_site'
All of this magic happens in your model's admin definition. You simply subclass your admin from
AdminViewsinstead of the standard
admin.ModelAdmin. In this example we have a custom view that does nothing but redirect the user to CNN and a direct URL link that goes to my company's homepage::
from django.contrib import admin from django.shortcuts import redirect
from admin_views.admin import AdminViews
from example_app.models import TestModel
class TestAdmin(AdminViews): admin_views = ( ('Redirect to CNN', 'redirect_to_cnn'), ('Go to revsys.com', 'http://www.revsys.com'), )
def redirect_to_cnn(self, *args, **kwargs): return redirect('http://www.cnn.com')
These will now show up in the admin below the usual Django admin model CRUD interfaces for
example_appwith a couple of different icons to distinquish between custom admin views and a direct URL link.
With this third-party developers need only instruct their users to install their app and
Hope you find it useful and as always feedback is certainly welcome.
.. image:: https://raw.githubusercontent.com/frankwiles/django-admin-views/master/example_project/example-screenshot.png
Blue link icon on direct URLs by http://www.doublejdesign.co.uk/
Admin view icon by http://www.fatcow.com/