#25387: ModelAdmin actions don't get access to the ActionForm -------------------------------+-------------------- Reporter: mbox | Owner: nobody Type: Bug | Status: new Component: contrib.admin | Version: master Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------- Setting an alternative ModelAdmin.action_form is supported, but ModelAdmin.actions don't get access to the form.
The naive approach is to rebind the form in the action: {{{ class ExampleAdmin(admin.ModelAdmin): action_form = ExampleForm actions = ['example_action'] def example_action(self, request, queryset): form = ExampleForm(request.POST) if form.is_valid(): # Process... }}} However, this doesn't work (`form.is_valid()` returns False) because there's special processing done on the `request.DATA` before the form is bound - see https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1205-L1220 So either this code has to be duplicated in the action, or the `request.POST` data processed manually. Neither seem ideal. A proposed fix would be to make the action_form that's bound in options.py be available as `self.bound_action_form` so that actions could access it. This would be entirely backwards-compatible. -- Ticket URL: <https://code.djangoproject.com/ticket/25387> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/047.1734401ff69f845d32f6ff621df482f0%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.