Opened 3 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#37176 closed Bug (fixed)

Action should be importable from django.contrib.admin.

Reported by: Mariusz Felisiak Owned by: Mariusz Felisiak
Component: contrib.admin Version: 6.1
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The new Action class should be importable from django.contrib.admin like ActionLocation.

Change History (5)

comment:1 by Natalia Bidart, 3 weeks ago

Triage Stage: UnreviewedAccepted

Thank you Mariusz, I think you proposal makes sense. I'm accepting but could you share your use case in the ticket for future reference?

in reply to:  1 comment:2 by Mariusz Felisiak, 3 weeks ago

Replying to Natalia Bidart:

Thank you Mariusz, I think you proposal makes sense. I'm accepting but could you share your use case in the ticket for future reference?

Sure, I'm adding actions dynamically based on the queryset, so separate action for each object, something like:

def get_actions(
        self,
        request,
        action_location=admin.ActionLocation.CHANGE_LIST,
    ):
        actions: dict[str, admin.Action] = super().get_actions(
            request,
            action_location=action_location, 
        )
        for some_obj in SomeModel.objects.all():
            name = f"add_{some_obj.pk}"
            description = f"Add {some_obj.name}"
            actions[name] = admin.Action(
                func=functools.partial(add_some_obj_action, some_obj=some_obj),
                name=name,
                description=description,
                plural_description=description,
                locations=[
                    admin.ActionLocation.CHANGE_LIST,
                    admin.ActionLocation.CHANGE_FORM,
                ],
            )
        return actions

I was surprised that I can use admin.ActionLocation but not admin.Action. The second thing is that our docs point to the django.contrib.admin module, that's why [source] is not visible for Action, check out https://docs.djangoproject.com/en/6.1/ref/contrib/admin/actions/#action.

comment:3 by Jacob Walls, 3 weeks ago

Severity: NormalRelease blocker
Triage Stage: AcceptedReady for checkin

comment:4 by Jacob Walls <jacobtylerwalls@…>, 3 weeks ago

Resolution: fixed
Status: assignedclosed

In 14988f14:

Fixed #37176 -- Made Action importable from django.contrib.admin.

comment:5 by Jacob Walls <jacobtylerwalls@…>, 3 weeks ago

In f88a6292:

[6.1.x] Fixed #37176 -- Made Action importable from django.contrib.admin.

Backport of 14988f14d94f9ce617f967d26b8ed2946172a140 from main.

Note: See TracTickets for help on using tickets.
Back to Top