Skip to main content

A simple Django middleware to reorder the admin app list and models from a single dict in

Project description

django-admin-applist-order

A simple Django middleware to reorder the admin app list and models from a single dict in settings.py.

Order the Django admin app list — the apps shown on the admin index, and the models within each app — from a single dict in your settings.py.

It works through a middleware that post-processes the admin's response, so you don't need to swap your AdminSite or change any admin registration. Add one line to MIDDLEWARE, define the setting, done.

Install

pip install django-admin-applist-order

Setup

Add the middleware (this is the only required step):

MIDDLEWARE = [
    # ...
    "django_admin_applist_order.middleware.AppListOrderMiddleware",
]

Usage

Define ADMIN_APPS_DISPLAY_ORDER in settings.py. Keys are app labels (the app's folder name, e.g. core, auth).

ADMIN_APPS_DISPLAY_ORDER = {
    "APP_NAME": ["MODEL1", "MODEL2", "MODEL3"],
}

Behaviour:

  • Apps listed in the dict appear first, in dict order. Apps not listed follow, sorted alphabetically by their display name.
  • Models listed for an app appear first, in that order, followed by any unlisted models sorted alphabetically.
  • An empty list means "show all of this app's models, sorted alphabetically".
  • If the setting is missing or empty, the package does nothing.

For example, ordering the blog app's models first, and then the auth app's models:

ADMIN_APPS_DISPLAY_ORDER = {
    "blog": ["Author", "Post"],  # these first, alphabetical order will show the rest of the blog app models
    "auth": [],  # listed app, but all models will appear by  alphabetical
}

How it works

Django builds the app list in the response context under app_list (the index page) and available_apps (the nav sidebar). The middleware reorders those lists in process_template_response according to your setting. Because it only touches the rendered context, it composes cleanly with a default admin.site or any custom AdminSite.

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_applist_order-0.7.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_admin_applist_order-0.7.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file django_admin_applist_order-0.7.0.tar.gz.

File metadata

File hashes

Hashes for django_admin_applist_order-0.7.0.tar.gz
Algorithm Hash digest
SHA256 28e03826b59325fe6d961df826a75423dd7578366b64f6153a994c2881ecf1d5
MD5 83fd1164e8bd7eacddb446c1913ca1be
BLAKE2b-256 0babe333d2a865f64f98ce6f39c62fdea616005db055ff1049e3039f4ce33f30

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_admin_applist_order-0.7.0.tar.gz:

Publisher: publish.yml on alon-p/django-admin-applist-order

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_admin_applist_order-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin_applist_order-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 507fb7c56a564d3a24eaf0848490e7b0ab4aab33d85a0553ee82385389d00b3a
MD5 125bc0bef75e89f30041231210602db6
BLAKE2b-256 89e4279327be8367cabeb51ad5ddb83615cd350fcfe37fb9d6c302977a88596c

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_admin_applist_order-0.7.0-py3-none-any.whl:

Publisher: publish.yml on alon-p/django-admin-applist-order

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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