Skip to main content

Add new pages to the Django admin.

Project description

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.

https://travis-ci.org/jsocol/django-adminplus.png?branch=master

Installing AdminPlus

Install from PyPI with pip:

pip install django-adminplus

Or get AdminPlus from GitHub with pip:

pip install -e git://github.com/jsocol/django-adminplus#egg=django-adminplus

And add adminplus to your installed apps:

INSTALLED_APPS = (
    # ...
    'adminplus',
    # ...
)

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():

# urls.py
from django.contrib import admin
from adminplus.sites import AdminSitePlus

admin.site = AdminSitePlus()
admin.autodiscover()

urlpatterns = patterns('',
    # ...
    # Include the admin URL conf as normal.
    (r'^admin', include(admin.site.urls)),
    # ...
)

If you’re using Django 1.7, you should also replace django.contrib.admin with django.contrib.admin.apps.SimpleAdminConfig in your installed apps, in order to disable the automatic auto-discovery:

INSTALLED_APPS = (
    # ...
    'django.contrib.admin.apps.SimpleAdminConfig',  # instead of 'django.contrib.admin'
    # ...
)

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:

# someapp/admin.py
# Assuming you've replaced django.contrib.admin.site as above.
from django.contrib import admin

def my_view(request, *args, **kwargs):
    pass
admin.site.register_view('somepath', view=my_view)

# And of course, this still works:
from someapp.models import MyModel
admin.site.register(MyModel)

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:

@admin.site.register_view('somepath')
def my_view(request):
    pass

register_view takes some optional arguments:

  • name: a friendly name for display in the list of custom views. For example:

    def my_view(request):
        """Does something fancy!"""
    admin.site.register_view('somepath', 'My Fancy Admin View!', view=my_view)
  • urlname: give a name to the urlpattern so it can be called by redirect(), reverse(), etc.

  • visible: a boolean or a callable returning one, that defines if the custom view is visible in the admin dashboard.

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

Project details


Download files

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

Source Distribution

django-adminplus-0.4.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

django_adminplus-0.4-py2.py3-none-any.whl (9.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-adminplus-0.4.tar.gz.

File metadata

File hashes

Hashes for django-adminplus-0.4.tar.gz
Algorithm Hash digest
SHA256 fbbfd7d35b44bb38779e569bce49902a2f90e7f392e84a3625fd7be29fb2072b
MD5 40b123c2c20cbac06cfcfb1e383177af
BLAKE2b-256 94d06c4e2dd6a4a88005c2903c44aaa5261bea2791591a5703c08f32e8db4648

See more details on using hashes here.

File details

Details for the file django_adminplus-0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_adminplus-0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 22f1bd20ade77fe5ccf12736d5a3e3c795aa05a9d87a75d5e9d6ae9d2baf20c7
MD5 02d5f3220d31b6543ccf0bf2a4cb5b96
BLAKE2b-256 9bf33fee57563941f0c81e64845a97fa9b10b60600e67d3bbe7897ceb959adc7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page