Skip to main content

Utility code and patterns.

Project description

Utility code and patterns.

  • Free software: BSD 2-Clause License

Installation

pip install django-admin-utils

You can also install the in-development version with:

pip install https://github.com/ionelmc/django-admin-utils/archive/master.zip

Documentation

Terse admin.py

from django.contrib import admin
from admin_utils import register, inline

from .models import MyModel, OtherModel

@register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    inlines = inline(OtherModel),

If you want custom admin sites:

customsite = admin.AdminSite()

@register(MyModel, site=customsite)
class MyModelAdmin(admin.ModelAdmin):
    inlines = inline(OherModel),

Mock admin (mount your views in admin using model wrappers)

Have you ever wanted a page in the admin that appears in the app list but you don’t have any models ? Now you can have that without patching up the admin Site or the templates. Just put this in your admin.py:

from django.urls import path
from admin_utils import make_admin_class

make_admin_class(
    app_label="test_app",
    model_name="Test1",
    urls=[
        path('', views.root, name='test_app_test1_changelist'),
        path('level1/', views.level1, name='level-1'),
        path('level1/level2/', views.level2, name='level-2'),
    ],
)

To use different admin site:

make_admin_class(
    site=customsite,
    app_label="test_app",
    model_name="Test1",
    urls=[
        path('', views.root, name='test_app_test1_changelist'),
        path('level1/', views.level1, name='level-1'),
        path('level1/level2/', views.level2, name='level-2'),
    ],
)

Alternatively you can mount a single view with a decorator:

from admin_utils import register_view

@register_view(
    site=customsite,
    app_label="test_app",
    model_name="Test1",
)
def root(request):
    ...

Admin mixins

admin_utils.mixins.FoldableListFilterAdminMixin

Adds nice filter toggling with cookie support. Largely based on django-foldable-list-filter but without the transition effect and no pictures.

Example:

from admin_utils.mixins import FoldableListFilterAdminMixin

class MyModelAdmin(FoldableListFilterAdminMixin, admin.ModelAdmin):
    pass

Looks like this:

Screenshort of FoldableListFilterAdminMixin

admin_utils.mixins.FullWidthAdminMixin

Make the changelist expand instead of having the width of the windows and having that nasty inner scrollbar. You never gonna notice that if your table is long !

Example:

from admin_utils.mixins import FoldableListFilterAdminMixin

class MyModelAdmin(FoldableListFilterAdminMixin, admin.ModelAdmin):
    pass

You probably didn’t even notice you had this problem:

Screenshort of FullWidthAdminMixin

Changelog

2.0.4 (2021-07-19)

  • Fix mock admin regression and add test.

2.0.3 (2021-07-19)

  • Make the mock admin behave as without editable permissions (implemented the missing has_view_permission method).

2.0.2 (2021-07-18)

  • Expose the fake hidden model as a fake_model attribute.

2.0.1 (2021-07-18)

  • Add missing import for admin_utils.register_view.

2.0.0 (2021-07-18)

  • Drop support for Python 2.7 and Django 1.11.

  • Added the register_view decorator.

  • Update examples/readme.

  • Various bugfixes.

1.0.0 (2021-07-14)

  • Fixed a bunch of regressions with Django 3.2.

0.3.0 (2014-02-02)

  • Forgot to add any details.

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-admin-utils-2.0.4.tar.gz (66.5 kB view details)

Uploaded Source

Built Distribution

django_admin_utils-2.0.4-py2.py3-none-any.whl (9.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-admin-utils-2.0.4.tar.gz.

File metadata

  • Download URL: django-admin-utils-2.0.4.tar.gz
  • Upload date:
  • Size: 66.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.6

File hashes

Hashes for django-admin-utils-2.0.4.tar.gz
Algorithm Hash digest
SHA256 245b88660ad283749c779163588f9ada1fdb44187a9ca2374a17dc235af44cfb
MD5 39fd0b11ce1b658e3de0e9aa741b30b5
BLAKE2b-256 f986c176dd3c844bf4f34cc72483327db63af4772d40ed44739242a70f0e43ab

See more details on using hashes here.

File details

Details for the file django_admin_utils-2.0.4-py2.py3-none-any.whl.

File metadata

  • Download URL: django_admin_utils-2.0.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.6

File hashes

Hashes for django_admin_utils-2.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5866d5989501769cb9def5ab1b9dc382dd2de39063f8913fdf54fb2bc835a77e
MD5 0854491f87c4a8a9411f46162153defb
BLAKE2b-256 1e1edb631b22ed07c1c773cf960c0c5a46e7683f1786f381a083299c8f5ac515

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