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(ChangeFirstName, "Change selected users' first name")
def change_first_name(
    modeladmin: Any,
    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-2.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

django_form_action-2.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_form_action-2.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for django_form_action-2.0.0.tar.gz
Algorithm Hash digest
SHA256 71e2855a3e09d7aef91dac227c36b97b325fa0fbc2d57044d6d9ee70066b1bf2
MD5 0e47410580dbebb2b282b8bf55e9ed25
BLAKE2b-256 472b4975d4177e81a7ba502f403feedcd211464fe8ac839e98d475b59cead7a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_form_action-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 964f110a6e2be3449cc06c4fbea672cf01161cccfbb4eaa7a5f652725aa80655
MD5 dfe8eb30e21f6c9f10c289f7b66b2135
BLAKE2b-256 04c0b79a7ec15ca0117deed9a9dc06e3db0b7285b53e4d7dc48aad2ed15f531d

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