#37176: Action should be importable from django.contrib.admin.
-------------------------------------+-------------------------------------
     Reporter:  Mariusz Felisiak     |                    Owner:  Mariusz
                                     |  Felisiak
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.admin        |                  Version:  6.1
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):

 Replying to [comment:1 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:

 {{{#!python
 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.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/37176#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019ed59a22e4-c678589f-b4a2-4105-9af7-50dd3ba2d49c-000000%40eu-central-1.amazonses.com.

Reply via email to