Add new pages to the Django admin.
Project description
Django Admin Plus
Custom Wiews for Django Admin made simple.
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.
📜 About and Motivation
Forked from https://github.com/jsocol/django-adminplus
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.
✨ Features
📋 Requirements
- Python 3.11 or higher
- Django 4.2 or higher
📦 Installation
Using pip
pip install django-sb-adminplus
Using uv
uv add django-sb-adminplus
🚀 Usage
And add django_sb_adminplus to your installed apps, and replace
django.contrib.admin with
django.contrib.admin.apps.SimpleAdminConfig:
INSTALLED_APPS = (
'django.contrib.admin.apps.SimpleAdminConfig',
# ...
'django_sb_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 django.urls import path
from django_sb_adminplus.sites import AdminSitePlus
admin.site = AdminSitePlus()
admin.autodiscover()
urlpatterns = [
# ...
# Include the admin URL conf as normal.
path('admin/', admin.site.urls),
# ...
]
Congratulations! You're now using AdminPlus.
Create custom views
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 byredirect(),reverse(), etc. The view will be added to theadminnamespace, so a urlname offoowould be reversed withreverse("admin:foo"). -
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.
Note
Views with URLs that match auto-discovered URLs (e.g. those created via ModelAdmins) will override the auto-discovered URL.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_sb_adminplus-0.7.0.tar.gz.
File metadata
- Download URL: django_sb_adminplus-0.7.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
038958e81274426dd1749b4bc583a3619fd58b97bc096103f62c5298c7038dc2
|
|
| MD5 |
8620601b7ca993baa1c0b2d2d1010590
|
|
| BLAKE2b-256 |
35fd6b742b0ad101117e315db7e53076bcbfe2914df0aee6b4dd42f843c2e59e
|
File details
Details for the file django_sb_adminplus-0.7.0-py3-none-any.whl.
File metadata
- Download URL: django_sb_adminplus-0.7.0-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2a42a6adfc8ecf1f5e98d8b2b3600d39cdd79beae077bd728b7bdd8fddcba73
|
|
| MD5 |
c6d7a54195aef10a01bfab3d019bcecc
|
|
| BLAKE2b-256 |
bc3e076d0cd0f7c75371f9ecbc1fd6e2ab632678fa8657937cdb5d46562b6815
|