Skip to main content

Django action with an intermediate page to parse data from a form

Project description

django-form-action

Django action with an intermediate page to parse data from a form

Installation

You can install the package via pip:

pip install django-form-action

Add django_form_action to INSTALLED_APPS.

Demo

Step 1 Step 2 Step 3

Usage

Example usage showing an action in UserAdmin which has an intermediate form that parses data on how to perform that action.

from typing import Any

from django.contrib import admin
from django.contrib import messages
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.db.models import QuerySet
from django.forms import CharField
from django.forms import Form
from django.http import HttpRequest

from django_form_action import form_action

admin.site.unregister(User)


class ChangeFirstName(Form):
    first_name = CharField()


@form_action(
    User,
    ChangeFirstName,
    "Change selected users' first name",
)
def change_first_name(
    modeladmin: "admin.ModelAdmin[User]",
    request: HttpRequest,
    queryset: QuerySet[User],
    form: ChangeFirstName,
):
    queryset.update(first_name=form.cleaned_data["first_name"])
    messages.add_message(
        request,
        messages.INFO,
        "Successfully changed the first name of selected users.",
    )


@admin.register(User)
class CustomUserAdmin(UserAdmin):
    actions = [change_first_name]

License

This project is licensed under the terms of the MIT license.

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_form_action-3.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

django_form_action-3.0.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file django_form_action-3.0.1.tar.gz.

File metadata

  • Download URL: django_form_action-3.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for django_form_action-3.0.1.tar.gz
Algorithm Hash digest
SHA256 b3f30d4522a5faf48fc15dc79e8759da2e3500003630f8f752dd5b46bc923b86
MD5 20acad0db99b9943e46b3cc5220df49a
BLAKE2b-256 e756bfe526592f4be1af45716d2e769626af27c90478f82292c2c401004e4785

See more details on using hashes here.

File details

Details for the file django_form_action-3.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_form_action-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1aee6bfd0a23894b87e6f5b223f8c6169d865cc860884147be39ba08d16cf278
MD5 7f6399f5621d33ea783ba1a6c5446b38
BLAKE2b-256 d9c593a4a56916b0a60595470a0a61d0adffc0c7ae3e6fbe0b7120ba4d57dfba

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