Skip to main content

Reusable helpers to register custom Django admin views and object tools.

Project description

django-boosted

Lightweight helpers to extend Django’s admin with extra views, custom forms, and the matching UI affordances (object tools, permissions, standard responses).

Features

  • @admin_boost_object_view decorator – fetches the target object, checks permissions, and builds the default context before rendering your template.
  • AdminBoostMixin – registers the custom URLs, protects them with admin_site.admin_view, and injects extra object-tool buttons into the change form.
  • Additional templates – a change form template that renders the injected buttons plus a simple “Hello” view as a teaching aid.

Installation

pip install django-boosted

Quick start

# app/admin.py
from django.contrib import admin
from django_boosted.mixins import AdminBoostMixin
from django_boosted.decorators import admin_boost_object_view
from .models import Client


class ClientAdmin(AdminBoostMixin, admin.ModelAdmin):
    boost_views = ["hello_view"]
    change_form_template = "admin_boost/change_form.html"

    @admin_boost_object_view(label="Say hello", template_name="admin_boost/hello.html")
    def hello_view(self, request, obj):
        return {"message": f"Hello {obj}!"}


admin.site.register(Client, ClientAdmin)

Include the provided templates in your TEMPLATES["DIRS"] (or copy them to customize).

Using forms with ForeignKey widgets

The decorator can automatically apply admin widgets (ForeignKeyRawIdWidget or AutocompleteSelect) to your form fields, using the same logic as ModelAdmin.change_view():

# app/admin.py
from django import forms
from django.contrib import admin, messages
from django.shortcuts import redirect
from django_boosted.mixins import AdminBoostMixin
from django_boosted.decorators import admin_boost_object_view
from .models import Company

class SyncFullGroupForm(forms.Form):
    group = forms.ModelChoiceField(queryset=Company.objects.all())
    option = forms.ChoiceField(
        label="sync method",
        choices=[("method1", "Method 1"), ("method2", "Method 2")],
    )

class CompanyAdmin(AdminBoostMixin, admin.ModelAdmin):
    boost_views = ["sync_full_group_view"]
    change_form_template = "admin_boost/change_form.html"

    @admin_boost_object_view(
        label="Sync Full Group",
        template_name="admin/sync_full_group.html",
        form=SyncFullGroupForm,
        raw_id_fields=["group"],  # Automatically applies ForeignKeyRawIdWidget
    )
    def sync_full_group_view(self, request, obj, form):
        if request.method == "POST" and form.is_valid():
            # Process form...
            group = form.cleaned_data["group"]
            option = form.cleaned_data["option"]
            # ... your logic ...
            self.message_user(request, "Sync completed", messages.SUCCESS)
            return redirect(obj.admin_change_url)
        return {}  # Return additional context if needed

The decorator handles:

  • Widget application (respects raw_id_fields and autocomplete_fields)
  • Form validation on POST
  • Adding the form to the template context
  • Backward compatibility (if your view doesn't accept a form parameter, it won't be passed)

Development commands

Run everything via ./service.py dev <command> or python dev.py <command>:

Command Description
./service.py dev install-dev or python dev.py install-dev create the venv and install the package editable with dev extras.
./service.py dev lint or python dev.py lint run Ruff + Black in check mode.
./service.py dev format or python dev.py format apply Ruff --fix then Black.
./service.py dev test or python dev.py test run pytest (with pytest-django).
./service.py dev build or python dev.py build clean then build wheel + sdist.
./service.py quality security or python dev.py security Bandit + Safety + pip-audit.
./service.py dev help or python dev.py help list all commands.

License

MIT — see the LICENSE file. Contributions welcome!

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_boosted-0.1.1.tar.gz (21.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_boosted-0.1.1-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

Details for the file django_boosted-0.1.1.tar.gz.

File metadata

  • Download URL: django_boosted-0.1.1.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for django_boosted-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7c3931f2d5d110f38b1c6e36bbcd9b457e09f89ff16c075c7cf0b81bd0cc27e1
MD5 1db774128c3236b8e2ad5d8e778fe9ff
BLAKE2b-256 f9d686f9d0cda736eee2b94f10efe7d0dd89fdde4edbde0e07cff25c9ddc1dbc

See more details on using hashes here.

File details

Details for the file django_boosted-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: django_boosted-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 30.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for django_boosted-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 120492a375334ed3a8e750e0b99ec94047fe7c4f7404d5321b14ae3e0f10e8de
MD5 48e88a2dcd085bf2416f61a111aa4805
BLAKE2b-256 4a58a82e9c36ab677cd4846a4b134644688f883b2c2bf0a514eebfe029b5e514

See more details on using hashes here.

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