Opened 6 years ago
Closed 6 years ago
#30259 closed New feature (fixed)
Support the use of admin_order_field on properties in the admin.
Reported by: | Tobias Wiese | Owned by: | Jani Tiainen |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The ModelAdmin
class allows to specify properties from the model in list_display
.
Normally non-fields cannot be sorted. This can be changed by setting admin_order_field
. This doesn't work on properties, while it is possible to do so with short_description
.
The code that checks for short_description
checks if it handles a property and returns attr.fget.short_description
if available.
The files that check for admin_order_field
do not handle the case that it might be a property.
The relevant files are probably:
Change History (10)
comment:1 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 6 years ago
Has patch: | set |
---|
comment:3 by , 6 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:4 by , 6 years ago
Summary: | admin_order_field not working with properties → Support the use of admin_order_field on properties in the admin. |
---|---|
Version: | 2.1 → master |
comment:5 by , 6 years ago
Type: | Bug → New feature |
---|
follow-up: 8 comment:7 by , 6 years ago
Easy pickings: | unset |
---|---|
Has patch: | unset |
Resolution: | fixed |
Severity: | Normal → Release blocker |
Status: | closed → new |
Triage Stage: | Ready for checkin → Accepted |
A selenium test fails after the patch: admin_views.tests.SeleniumTests.test_list_editable_raw_id_fields
:
Traceback (most recent call last): File "/home/tim/code/django/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/home/tim/code/django/django/core/handlers/base.py", line 145, in _get_response response = self.process_exception_by_middleware(e, request) File "/home/tim/code/django/django/core/handlers/base.py", line 143, in _get_response response = response.render() File "/home/tim/code/django/django/template/response.py", line 106, in render self.content = self.rendered_content File "/home/tim/code/django/django/template/response.py", line 83, in rendered_content content = template.render(context, self._request) File "/home/tim/code/django/django/template/backends/django.py", line 61, in render return self.template.render(context) File "/home/tim/code/django/django/template/base.py", line 171, in render return self._render(context) File "/home/tim/code/django/django/test/utils.py", line 95, in instrumented_test_render return self.nodelist.render(context) File "/home/tim/code/django/django/template/base.py", line 937, in render bit = node.render_annotated(context) File "/home/tim/code/django/django/template/base.py", line 904, in render_annotated return self.render(context) File "/home/tim/code/django/django/template/loader_tags.py", line 150, in render return compiled_parent._render(context) File "/home/tim/code/django/django/test/utils.py", line 95, in instrumented_test_render return self.nodelist.render(context) File "/home/tim/code/django/django/template/base.py", line 937, in render bit = node.render_annotated(context) File "/home/tim/code/django/django/template/base.py", line 904, in render_annotated return self.render(context) File "/home/tim/code/django/django/template/loader_tags.py", line 150, in render return compiled_parent._render(context) File "/home/tim/code/django/django/test/utils.py", line 95, in instrumented_test_render return self.nodelist.render(context) File "/home/tim/code/django/django/template/base.py", line 937, in render bit = node.render_annotated(context) File "/home/tim/code/django/django/template/base.py", line 904, in render_annotated return self.render(context) File "/home/tim/code/django/django/template/loader_tags.py", line 62, in render result = block.nodelist.render(context) File "/home/tim/code/django/django/template/base.py", line 937, in render bit = node.render_annotated(context) File "/home/tim/code/django/django/template/base.py", line 904, in render_annotated return self.render(context) File "/home/tim/code/django/django/template/loader_tags.py", line 62, in render result = block.nodelist.render(context) File "/home/tim/code/django/django/template/base.py", line 937, in render bit = node.render_annotated(context) File "/home/tim/code/django/django/template/base.py", line 904, in render_annotated return self.render(context) File "/home/tim/code/django/django/contrib/admin/templatetags/base.py", line 33, in render return super().render(context) File "/home/tim/code/django/django/template/library.py", line 214, in render _dict = self.func(*resolved_args, **resolved_kwargs) File "/home/tim/code/django/django/contrib/admin/templatetags/admin_list.py", line 332, in result_list headers = list(result_headers(cl)) File "/home/tim/code/django/django/contrib/admin/templatetags/admin_list.py", line 133, in result_headers admin_order_field = getattr(attr.fget, 'admin_order_field') AttributeError: 'function' object has no attribute 'admin_order_field'
comment:8 by , 6 years ago
Replying to Tim Graham:
A selenium test fails after the patch:
admin_views.tests.SeleniumTests.test_list_editable_raw_id_fields
:
File "/home/tim/code/django/django/contrib/admin/templatetags/admin_list.py", line 133, in result_headers admin_order_field = getattr(attr.fget, 'admin_order_field') AttributeError: 'function' object has no attribute 'admin_order_field'
Apparently that getattr
should be:
admin_order_field = getattr(attr.fget, 'admin_order_field', None)
PR