[Django] #34724: Allow passing kwargs to django.contrib.admin.decorators.display

5 views
Skip to first unread message

Django

unread,
Jul 19, 2023, 2:24:58 PM7/19/23
to django-...@googlegroups.com
#34724: Allow passing kwargs to django.contrib.admin.decorators.display
--------------------------------------------+------------------------
Reporter: Abdullah Alaqeel | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
--------------------------------------------+------------------------
There are many packages that depend on assigning custom params to
ModelAdmin methods. One package we use regularly is
[https://github.com/lukasvinclav/django-admin-actions django-admin-
actions] which requires writing something like:

{{{
@admin.register(ExampleModel)
class CustomAdmin(ActionsModelAdmin):
actions_list = ('custom_list_action', )

def custom_list_action(self, request):
# custom logic here
return redirect(reverse_lazy('admin:APP_MODEL_changelist'))
custom_list_action.short_description = _('Custom name')
custom_list_action.url_path = 'clean-url-path-1'
}}}

However, when using django.contrib.admin.decorators.display, it will be:

{{{
@admin.register(ExampleModel)
class CustomAdmin(ActionsModelAdmin):
actions_list = ('custom_list_action', )

@admin.display(description=_('Custom name'))
def custom_list_action(self, request):
# custom logic here
return redirect(reverse_lazy('admin:APP_MODEL_changelist'))
custom_list_action.url_path = 'clean-url-path-1'
}}}

It would be really helpful/clean if we can pass any kwargs we want to the
decorator, so that the code looks like:
{{{
@admin.register(ExampleModel)
class CustomAdmin(ActionsModelAdmin):
actions_list = ('custom_list_action', )

@admin.display(description=_('Custom name'), url_path='clean-url-
path-1')
def custom_list_action(self, request):
# custom logic here
return redirect(reverse_lazy('admin:APP_MODEL_changelist'))
}}}

I know that creating a custom decorator (either by the users or the
package maintainers) is trivial but I think there is value to the
community to add the kwargs support natively.

--
Ticket URL: <https://code.djangoproject.com/ticket/34724>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 19, 2023, 2:34:24 PM7/19/23
to django-...@googlegroups.com
#34724: Allow passing kwargs to django.contrib.admin.decorators.display
----------------------------------+--------------------------------------

Reporter: Abdullah Alaqeel | Owner: nobody
Type: New feature | Status: closed
Component: contrib.admin | Version: dev
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* cc: Nick Pope (added)
* status: new => closed
* resolution: => wontfix
* easy: 1 => 0


Comment:

> I know that creating a custom decorator (either by the users or the
package maintainers) is trivial but I think there is value to the
community to add the kwargs support natively.

Thanks for the ticket, however I don't agree. Custom `kwargs` need to be
handled somehow, and Django (i.e. `@admin.display`) will not handle them
for users, which can cause confusion (check out #20744).

--
Ticket URL: <https://code.djangoproject.com/ticket/34724#comment:1>

Reply all
Reply to author
Forward
0 new messages