Opened 18 years ago
Closed 14 years ago
#3397 closed (fixed)
Add tests for 'Allow DB-level ordering by non-fields in changelist view' admin functionality
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Keywords: | nfa-changelist | |
Cc: | djangotrac@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The attached patch lets you specify a field to sort a non-field
column in the admin list view. I created it for the django-multilingual
library, but there are more cases where this could prove useful.
See the example in docs/model-api.txt diff.
Attachments (3)
Change History (20)
by , 18 years ago
Attachment: | patch_allow_ordering_by_nonfields.diff added |
---|
comment:2 by , 18 years ago
Summary: | [patch] Allow ordering by non-fields in admin list view → [patch] Allow DB-level ordering by non-fields in admin list view |
---|
Renamed the ticket to clarify it.
comment:3 by , 18 years ago
Triage Stage: | Design decision needed → Ready for checkin |
---|
This seems reasonable. It's a little bit hard to understand until you read the docs, but the example gets the point across. The documentation paragraph probably needs a rewrite -- it feels a bit awkward at the moment. But I'm too tired to get it right now; we just need to remember to tweak that before checking in. Other than that, this looks fine.
comment:4 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:5 by , 18 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Triage Stage: | Ready for checkin → Unreviewed |
This doesn't quite work correctly. It allows clicking on the column title to sort in ascending order but it doesn't display the triangle and a second click will sort ascending rather than descending.
The fix is for admin_list.py line 104 to also check if the admin_order_field equals cl.order_field.
Patch attached.
by , 18 years ago
Attachment: | admin_list.diff added |
---|
Patch to allow descending sort of non-DB fields
comment:6 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
by , 18 years ago
Attachment: | patch_allow_ordering_by_nonfields_fix.diff added |
---|
comment:7 by , 18 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Unless I'm mistaken, in django/contrib/admin/views/main.py in section added in this patch, there(see my patch patch_allow_ordering_by_nonfields_fix.diff) should be AttributeError instead of IndexError (IndexError cannot raise there and IMO author meant there AttributeError)
comment:8 by , 18 years ago
glin: you are right, it should be an AttributeError. I missed it because usually this code path is not executed at all, but it is a bug and should be fixed.
comment:9 by , 17 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
The file "patch_allow_ordering_by_nonfields_fix.diff" should be checked in following the last two comments (i.e. should be AttributeError not IndexError.
comment:10 by , 17 years ago
comment:11 by , 17 years ago
Has patch: | unset |
---|---|
Needs tests: | set |
Triage Stage: | Ready for checkin → Accepted |
Just because the other parts of the admin don't have tests doesn't mean that we should continue the trend.
comment:13 by , 17 years ago
Keywords: | nfa-changelist added |
---|
follow-up: 15 comment:14 by , 16 years ago
Can someone verify if this broken on trunk? It sounds likely it will work just fine, but needs really needs a test case.
comment:15 by , 16 years ago
comment:16 by , 16 years ago
Cc: | added |
---|
comment:17 by , 14 years ago
Summary: | [patch] Allow DB-level ordering by non-fields in admin list view → Add tests for 'Allow DB-level ordering by non-fields in changelist view' admin functionality |
---|
comment:18 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
In the intervening years since this was reopened, tests have been added for admin_order_field, see for example: http://code.djangoproject.com/browser/django/tags/releases/1.2.5/tests/regressiontests/admin_views/tests.py#L192
I think it's OK to close this one as fixed now.
Diff against trunk