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

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.0.tar.gz (3.9 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.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_form_action-3.0.0.tar.gz
  • Upload date:
  • Size: 3.9 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.0.tar.gz
Algorithm Hash digest
SHA256 f6067f5e3c21d291cb9dd6052c9f02fcf556afe7847ebf36768051d3b4867fc8
MD5 134487be1532928aa1c6009d4bcf8530
BLAKE2b-256 5b9120679d9b9cd2751d383da0d70d2707a81aea1cd9476f26eb99eea585e332

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_form_action-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c1cd904f28feed85a82860b39c8de417130d43fd85f01ace8cc9a3b8ae5ad26
MD5 0547f1fa52d361a724c63bc8064a4766
BLAKE2b-256 52333d21f2e56f47089d15b59090b0278f392925a6de6721a8b4f295239c15af

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