Opened 16 months ago
Closed 16 months ago
#34724 closed New feature (wontfix)
Allow passing kwargs to django.contrib.admin.decorators.display
Reported by: | Abdullah Alaqeel | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Nick Pope | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
There are many packages that depend on assigning custom params to ModelAdmin methods. One package we use regularly is 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.
Change History (1)
comment:1 by , 16 months ago
Cc: | added |
---|---|
Easy pickings: | unset |
Resolution: | → wontfix |
Status: | new → closed |
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).